diff --git a/CHANGELOG.md b/CHANGELOG.md index 06e562f3e89..0ee3124d32b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ If possible, provide tooling that performs the changes, e.g. a shell-script. * Added `seqan3::views::char_strictly_to`. Behaves like `seqan3::views::char_to`, but throws on invalid input ([\#2898](https://github.com/seqan/seqan3/pull/2898)). * Improved performance of vector assignment for alphabets ([\#3038](https://github.com/seqan/seqan3/pull/3038)). + * Char literals returning std::vector are now constexpr if supported by the compiler + ([\#3073](https://github.com/seqan/seqan3/pull/3073)). #### I/O * Added `seqan3::sequence_file_option::fasta_ignore_blanks_before_id` to ignore blanks before IDs when reading FASTA diff --git a/include/seqan3/alphabet/aminoacid/aa10li.hpp b/include/seqan3/alphabet/aminoacid/aa10li.hpp index e0be386b82c..26cf447ca07 100644 --- a/include/seqan3/alphabet/aminoacid/aa10li.hpp +++ b/include/seqan3/alphabet/aminoacid/aa10li.hpp @@ -228,7 +228,7 @@ constexpr aa10li operator""_aa10li(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline aa10li_vector operator""_aa10li(char const * const s, size_t const n) +SEQAN3_WORKAROUND_LITERAL aa10li_vector operator""_aa10li(char const * const s, size_t const n) { aa10li_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/aminoacid/aa10murphy.hpp b/include/seqan3/alphabet/aminoacid/aa10murphy.hpp index 7f95fb972cc..7ff97abe495 100644 --- a/include/seqan3/alphabet/aminoacid/aa10murphy.hpp +++ b/include/seqan3/alphabet/aminoacid/aa10murphy.hpp @@ -226,7 +226,7 @@ constexpr aa10murphy operator""_aa10murphy(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline aa10murphy_vector operator""_aa10murphy(char const * const s, size_t const n) +SEQAN3_WORKAROUND_LITERAL aa10murphy_vector operator""_aa10murphy(char const * const s, size_t const n) { aa10murphy_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/aminoacid/aa20.hpp b/include/seqan3/alphabet/aminoacid/aa20.hpp index dd92b7814f1..93c92b88815 100644 --- a/include/seqan3/alphabet/aminoacid/aa20.hpp +++ b/include/seqan3/alphabet/aminoacid/aa20.hpp @@ -187,7 +187,7 @@ constexpr aa20 operator""_aa20(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline aa20_vector operator""_aa20(char const * const s, size_t const n) +SEQAN3_WORKAROUND_LITERAL aa20_vector operator""_aa20(char const * const s, size_t const n) { aa20_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/aminoacid/aa27.hpp b/include/seqan3/alphabet/aminoacid/aa27.hpp index 372aac2d4de..f0d7cd34f9c 100644 --- a/include/seqan3/alphabet/aminoacid/aa27.hpp +++ b/include/seqan3/alphabet/aminoacid/aa27.hpp @@ -158,7 +158,7 @@ constexpr aa27 operator""_aa27(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline aa27_vector operator""_aa27(char const * const s, size_t const n) +SEQAN3_WORKAROUND_LITERAL aa27_vector operator""_aa27(char const * const s, size_t const n) { aa27_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/dna15.hpp b/include/seqan3/alphabet/nucleotide/dna15.hpp index e8e09ba097f..aa4c785d7d6 100644 --- a/include/seqan3/alphabet/nucleotide/dna15.hpp +++ b/include/seqan3/alphabet/nucleotide/dna15.hpp @@ -203,7 +203,7 @@ constexpr dna15 operator""_dna15(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline dna15_vector operator""_dna15(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL dna15_vector operator""_dna15(char const * s, std::size_t n) { dna15_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/dna16sam.hpp b/include/seqan3/alphabet/nucleotide/dna16sam.hpp index 5012241b4bf..dbd5ab6eb47 100644 --- a/include/seqan3/alphabet/nucleotide/dna16sam.hpp +++ b/include/seqan3/alphabet/nucleotide/dna16sam.hpp @@ -190,7 +190,7 @@ constexpr dna16sam operator""_dna16sam(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline dna16sam_vector operator""_dna16sam(char const * s, size_t n) +SEQAN3_WORKAROUND_LITERAL dna16sam_vector operator""_dna16sam(char const * s, size_t n) { dna16sam_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/dna3bs.hpp b/include/seqan3/alphabet/nucleotide/dna3bs.hpp index 08604a55515..ada5ff99745 100644 --- a/include/seqan3/alphabet/nucleotide/dna3bs.hpp +++ b/include/seqan3/alphabet/nucleotide/dna3bs.hpp @@ -207,7 +207,7 @@ constexpr dna3bs operator""_dna3bs(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline dna3bs_vector operator""_dna3bs(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL dna3bs_vector operator""_dna3bs(char const * s, std::size_t n) { dna3bs_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/dna4.hpp b/include/seqan3/alphabet/nucleotide/dna4.hpp index e7695a0d413..faafd90a528 100644 --- a/include/seqan3/alphabet/nucleotide/dna4.hpp +++ b/include/seqan3/alphabet/nucleotide/dna4.hpp @@ -249,7 +249,7 @@ constexpr dna4 operator""_dna4(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline dna4_vector operator""_dna4(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL dna4_vector operator""_dna4(char const * s, std::size_t n) { dna4_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/dna5.hpp b/include/seqan3/alphabet/nucleotide/dna5.hpp index 6005286ddfe..52b85df0ff3 100644 --- a/include/seqan3/alphabet/nucleotide/dna5.hpp +++ b/include/seqan3/alphabet/nucleotide/dna5.hpp @@ -193,7 +193,7 @@ constexpr dna5 operator""_dna5(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline dna5_vector operator""_dna5(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL dna5_vector operator""_dna5(char const * s, std::size_t n) { dna5_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/rna15.hpp b/include/seqan3/alphabet/nucleotide/rna15.hpp index 83a73d811d6..3848da3a150 100644 --- a/include/seqan3/alphabet/nucleotide/rna15.hpp +++ b/include/seqan3/alphabet/nucleotide/rna15.hpp @@ -156,7 +156,7 @@ constexpr rna15 operator""_rna15(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline rna15_vector operator""_rna15(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL rna15_vector operator""_rna15(char const * s, std::size_t n) { rna15_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/rna4.hpp b/include/seqan3/alphabet/nucleotide/rna4.hpp index 26e9360267f..1472cfb2e93 100644 --- a/include/seqan3/alphabet/nucleotide/rna4.hpp +++ b/include/seqan3/alphabet/nucleotide/rna4.hpp @@ -153,7 +153,7 @@ constexpr rna4 operator""_rna4(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline rna4_vector operator""_rna4(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL rna4_vector operator""_rna4(char const * s, std::size_t n) { rna4_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/nucleotide/rna5.hpp b/include/seqan3/alphabet/nucleotide/rna5.hpp index 86fec2e9dd0..2e7e7202598 100644 --- a/include/seqan3/alphabet/nucleotide/rna5.hpp +++ b/include/seqan3/alphabet/nucleotide/rna5.hpp @@ -153,7 +153,7 @@ constexpr rna5 operator""_rna5(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline rna5_vector operator""_rna5(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL rna5_vector operator""_rna5(char const * s, std::size_t n) { rna5_vector r; r.resize(n); diff --git a/include/seqan3/alphabet/quality/phred42.hpp b/include/seqan3/alphabet/quality/phred42.hpp index 4b569d5a6b8..76abc4189d5 100644 --- a/include/seqan3/alphabet/quality/phred42.hpp +++ b/include/seqan3/alphabet/quality/phred42.hpp @@ -120,7 +120,7 @@ constexpr phred42 operator""_phred42(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline std::vector operator""_phred42(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_phred42(char const * s, std::size_t n) { std::vector r; r.resize(n); diff --git a/include/seqan3/alphabet/quality/phred63.hpp b/include/seqan3/alphabet/quality/phred63.hpp index 5201715f1e5..c94ae18b204 100644 --- a/include/seqan3/alphabet/quality/phred63.hpp +++ b/include/seqan3/alphabet/quality/phred63.hpp @@ -120,7 +120,7 @@ constexpr phred63 operator""_phred63(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline std::vector operator""_phred63(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_phred63(char const * s, std::size_t n) { std::vector r; r.resize(n); diff --git a/include/seqan3/alphabet/quality/phred68solexa.hpp b/include/seqan3/alphabet/quality/phred68solexa.hpp index f02faae0e9a..d6d3182b7e0 100644 --- a/include/seqan3/alphabet/quality/phred68solexa.hpp +++ b/include/seqan3/alphabet/quality/phred68solexa.hpp @@ -113,7 +113,7 @@ constexpr phred68solexa operator""_phred68solexa(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline std::vector operator""_phred68solexa(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_phred68solexa(char const * s, std::size_t n) { std::vector r; r.resize(n); diff --git a/include/seqan3/alphabet/quality/phred94.hpp b/include/seqan3/alphabet/quality/phred94.hpp index ea5b6b61442..c96f4169fe7 100644 --- a/include/seqan3/alphabet/quality/phred94.hpp +++ b/include/seqan3/alphabet/quality/phred94.hpp @@ -117,7 +117,7 @@ constexpr phred94 operator""_phred94(char const c) noexcept * * \stableapi{Since version 3.1.} */ -inline std::vector operator""_phred94(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_phred94(char const * s, std::size_t n) { std::vector r; r.resize(n); diff --git a/include/seqan3/alphabet/structure/dot_bracket3.hpp b/include/seqan3/alphabet/structure/dot_bracket3.hpp index b969e8174e5..8328883db9c 100644 --- a/include/seqan3/alphabet/structure/dot_bracket3.hpp +++ b/include/seqan3/alphabet/structure/dot_bracket3.hpp @@ -198,7 +198,7 @@ constexpr dot_bracket3 operator""_db3(char const ch) noexcept * * \experimentalapi{Experimental since version 3.1.} */ -inline std::vector operator""_db3(char const * str, std::size_t len) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_db3(char const * str, std::size_t len) { std::vector vec; vec.resize(len); diff --git a/include/seqan3/alphabet/structure/dssp9.hpp b/include/seqan3/alphabet/structure/dssp9.hpp index 7e7ac1bf497..ccb54db08cb 100644 --- a/include/seqan3/alphabet/structure/dssp9.hpp +++ b/include/seqan3/alphabet/structure/dssp9.hpp @@ -149,7 +149,7 @@ constexpr dssp9 operator""_dssp9(char const ch) noexcept * * \experimentalapi{Experimental since version 3.1.} */ -inline std::vector operator""_dssp9(char const * str, std::size_t len) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_dssp9(char const * str, std::size_t len) { std::vector vec; vec.resize(len); diff --git a/include/seqan3/alphabet/structure/wuss.hpp b/include/seqan3/alphabet/structure/wuss.hpp index 43c0628b1eb..7aff8ad75a4 100644 --- a/include/seqan3/alphabet/structure/wuss.hpp +++ b/include/seqan3/alphabet/structure/wuss.hpp @@ -269,7 +269,7 @@ constexpr wuss51 operator""_wuss51(char const ch) noexcept * * \experimentalapi{Experimental since version 3.1.} */ -inline std::vector operator""_wuss51(char const * str, std::size_t len) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_wuss51(char const * str, std::size_t len) { std::vector vec; vec.resize(len); diff --git a/include/seqan3/core/platform.hpp b/include/seqan3/core/platform.hpp index 39daf009e2f..903dbafff1a 100644 --- a/include/seqan3/core/platform.hpp +++ b/include/seqan3/core/platform.hpp @@ -273,6 +273,13 @@ static_assert(sdsl::sdsl_version_major == 3, "Only version 3 of the SDSL is supp # endif #endif +//!\brief Our char literals returning std::vector should be constexpr if constexpr std::vector is supported. +#if defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L +# define SEQAN3_WORKAROUND_LITERAL constexpr +#else +# define SEQAN3_WORKAROUND_LITERAL inline +#endif + #if SEQAN3_DOXYGEN_ONLY(1) 0 //!\brief This disables the warning you would get if -D_GLIBCXX_USE_CXX11_ABI=0 is set. # define SEQAN3_DISABLE_LEGACY_STD_DIAGNOSTIC diff --git a/include/seqan3/io/sam_file/detail/cigar.hpp b/include/seqan3/io/sam_file/detail/cigar.hpp index 6eb231a49b3..ce75ffa6bc5 100644 --- a/include/seqan3/io/sam_file/detail/cigar.hpp +++ b/include/seqan3/io/sam_file/detail/cigar.hpp @@ -145,7 +145,7 @@ inline void update_alignment_lengths(int32_t & ref_length, * `{[(H,1), (M,4), (D,1), (M,2), (S,2)], 7, 6}`. */ template -inline std::tuple, int32_t, int32_t> parse_cigar(cigar_input_type && cigar_input) +SEQAN3_WORKAROUND_LITERAL std::tuple, int32_t, int32_t> parse_cigar(cigar_input_type && cigar_input) { std::vector operations{}; std::array buffer{}; // buffer to parse numbers with from_chars. Biggest number should fit in uint64_t diff --git a/test/documentation/seqan3_doxygen_cfg.in b/test/documentation/seqan3_doxygen_cfg.in index 41a49c58cb6..2a3ea9f9b09 100644 --- a/test/documentation/seqan3_doxygen_cfg.in +++ b/test/documentation/seqan3_doxygen_cfg.in @@ -57,7 +57,8 @@ PREDEFINED = "CEREAL_SERIALIZE_FUNCTION_NAME=serialize" \ "CEREAL_SAVE_MINIMAL_FUNCTION_NAME=save_minimal" \ "SEQAN3_DOXYGEN_ONLY(x)= x" \ "${SEQAN3_DOXYGEN_PREDEFINED_NDEBUG}" \ - "__cpp_lib_three_way_comparison=1" + "__cpp_lib_three_way_comparison=1" \ + "SEQAN3_WORKAROUND_LITERAL=constexpr" EXPAND_AS_DEFINED = SEQAN3_CPO_OVERLOAD_BODY SEQAN3_CPO_OVERLOAD diff --git a/test/include/seqan3/test/literal/cigar_literal.hpp b/test/include/seqan3/test/literal/cigar_literal.hpp index 0a2c50aa32f..274950dae55 100644 --- a/test/include/seqan3/test/literal/cigar_literal.hpp +++ b/test/include/seqan3/test/literal/cigar_literal.hpp @@ -19,7 +19,7 @@ namespace seqan3::test { -inline std::vector operator""_cigar(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector operator""_cigar(char const * s, std::size_t n) { return std::get<0>(seqan3::detail::parse_cigar(std::string_view{s, n})); } diff --git a/test/include/seqan3/test/literal/gapped_dna5_literal.hpp b/test/include/seqan3/test/literal/gapped_dna5_literal.hpp index 13da30ec0bb..0459c97541d 100644 --- a/test/include/seqan3/test/literal/gapped_dna5_literal.hpp +++ b/test/include/seqan3/test/literal/gapped_dna5_literal.hpp @@ -18,7 +18,8 @@ namespace seqan3::test { -inline std::vector> operator""_gapped_dna5(char const * s, std::size_t n) +SEQAN3_WORKAROUND_LITERAL std::vector> operator""_gapped_dna5(char const * s, + std::size_t n) { std::vector> r; r.resize(n);