Skip to content

Commit

Permalink
[MISC] Make literals conditionally constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
eseiler committed Oct 20, 2022
1 parent e723338 commit ff912ef
Show file tree
Hide file tree
Showing 25 changed files with 34 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/aminoacid/aa10li.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/aminoacid/aa10murphy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/aminoacid/aa20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/aminoacid/aa27.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/dna15.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/dna16sam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/dna3bs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/dna4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/dna5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/rna15.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/rna4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/nucleotide/rna5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/quality/phred42.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ constexpr phred42 operator""_phred42(char const c) noexcept
*
* \stableapi{Since version 3.1.}
*/
inline std::vector<phred42> operator""_phred42(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<phred42> operator""_phred42(char const * s, std::size_t n)
{
std::vector<phred42> r;
r.resize(n);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/quality/phred63.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ constexpr phred63 operator""_phred63(char const c) noexcept
*
* \stableapi{Since version 3.1.}
*/
inline std::vector<phred63> operator""_phred63(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<phred63> operator""_phred63(char const * s, std::size_t n)
{
std::vector<phred63> r;
r.resize(n);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/quality/phred68solexa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ constexpr phred68solexa operator""_phred68solexa(char const c) noexcept
*
* \stableapi{Since version 3.1.}
*/
inline std::vector<phred68solexa> operator""_phred68solexa(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<phred68solexa> operator""_phred68solexa(char const * s, std::size_t n)
{
std::vector<phred68solexa> r;
r.resize(n);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/quality/phred94.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ constexpr phred94 operator""_phred94(char const c) noexcept
*
* \stableapi{Since version 3.1.}
*/
inline std::vector<phred94> operator""_phred94(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<phred94> operator""_phred94(char const * s, std::size_t n)
{
std::vector<phred94> r;
r.resize(n);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/structure/dot_bracket3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ constexpr dot_bracket3 operator""_db3(char const ch) noexcept
*
* \experimentalapi{Experimental since version 3.1.}
*/
inline std::vector<dot_bracket3> operator""_db3(char const * str, std::size_t len)
SEQAN3_WORKAROUND_LITERAL std::vector<dot_bracket3> operator""_db3(char const * str, std::size_t len)
{
std::vector<dot_bracket3> vec;
vec.resize(len);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/structure/dssp9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ constexpr dssp9 operator""_dssp9(char const ch) noexcept
*
* \experimentalapi{Experimental since version 3.1.}
*/
inline std::vector<dssp9> operator""_dssp9(char const * str, std::size_t len)
SEQAN3_WORKAROUND_LITERAL std::vector<dssp9> operator""_dssp9(char const * str, std::size_t len)
{
std::vector<dssp9> vec;
vec.resize(len);
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/alphabet/structure/wuss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ constexpr wuss51 operator""_wuss51(char const ch) noexcept
*
* \experimentalapi{Experimental since version 3.1.}
*/
inline std::vector<wuss51> operator""_wuss51(char const * str, std::size_t len)
SEQAN3_WORKAROUND_LITERAL std::vector<wuss51> operator""_wuss51(char const * str, std::size_t len)
{
std::vector<wuss51> vec;
vec.resize(len);
Expand Down
7 changes: 7 additions & 0 deletions include/seqan3/core/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/seqan3/io/sam_file/detail/cigar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename cigar_input_type>
inline std::tuple<std::vector<cigar>, int32_t, int32_t> parse_cigar(cigar_input_type && cigar_input)
SEQAN3_WORKAROUND_LITERAL std::tuple<std::vector<cigar>, int32_t, int32_t> parse_cigar(cigar_input_type && cigar_input)
{
std::vector<cigar> operations{};
std::array<char, 20> buffer{}; // buffer to parse numbers with from_chars. Biggest number should fit in uint64_t
Expand Down
3 changes: 2 additions & 1 deletion test/documentation/seqan3_doxygen_cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/include/seqan3/test/literal/cigar_literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
namespace seqan3::test
{

inline std::vector<cigar> operator""_cigar(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<cigar> operator""_cigar(char const * s, std::size_t n)
{
return std::get<0>(seqan3::detail::parse_cigar(std::string_view{s, n}));
}
Expand Down
3 changes: 2 additions & 1 deletion test/include/seqan3/test/literal/gapped_dna5_literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
namespace seqan3::test
{

inline std::vector<seqan3::gapped<seqan3::dna5>> operator""_gapped_dna5(char const * s, std::size_t n)
SEQAN3_WORKAROUND_LITERAL std::vector<seqan3::gapped<seqan3::dna5>> operator""_gapped_dna5(char const * s,
std::size_t n)
{
std::vector<seqan3::gapped<seqan3::dna5>> r;
r.resize(n);
Expand Down

0 comments on commit ff912ef

Please sign in to comment.