seqan / product_backlog

This repository is used as product backlog for all SeqAn relevant backlog items. This is intended to organise the work for the team.
2 stars 1 forks source link

Add constexpr to char literals creating a vector #399

Closed eseiler closed 1 year ago

eseiler commented 3 years ago

The only thing I want to add is that we should also add constexpr to

inline aa10li_vector operator""_aa10li(char const * const s, size_t const n)

if the compiler supports constexpr std::vector.

But this should be another PR in any case.

Originally posted by @eseiler in https://github.com/seqan/seqan3/issues/2819#issuecomment-925592163


@eseiler Good point!

Originally posted by @marehr in https://github.com/seqan/seqan3/issues/2819#issuecomment-925598614


@eseiler Good point!

We could probably do something like this

#if defined(__cpp_lib_constexpr_vector) && __cpp_lib_constexpr_vector >= 201907L
#    define SEQAN3_CHAR_LITERAL_VECTOR constexpr
#else
#    define SEQAN3_CHAR_LITERAL_VECTOR inline
#endif

However, only MSVC implements constexpr for std::vector.

https://godbolt.org/z/EKGxYnEas

Originally posted by @eseiler in https://github.com/seqan/seqan3/issues/2819#issuecomment-925619276

marehr commented 3 years ago

As constexpr is a best effort declaration in the sense that in doubt it won't compile, we could simply declare it constexpr without any macros.

eseiler commented 3 years ago

As constexpr is a best effort declaration in the sense that in doubt it won't compile, we could simply declare it constexpr without any macros.

But the function body still needs to be a valid, (possibly) constant expression. And because we construct the vector inside the literal, it doesn't work.

https://godbolt.org/z/394KTozjc

marehr commented 3 years ago

Thank you, I thought it would just work, but you right :(