I could not find a relevant question/answer for this one. Consider this:
// constexpr declares intent
template <typename T> inline constexpr const bool probe (T const &) noexcept { return false; }
template <typename T> inline constexpr const bool probe (T const *) noexcept { return true; }
template <typename T> inline constexpr const bool probe (T &&) noexcept = delete ;
template <typename T> inline constexpr const bool probe (T) noexcept = delete ;
As we all know and expect the following do work as expected, at compile time:
constexpr inline const char * holla_ = "Hola!";
// OK
static_assert(probe(holla_));
// OK
static_assert(probe("string literal"));
And these too:
inline const char buff[]{"ABCD"};
// OK -- although `buff` is not compile time array
static_assert(probe(buff));
constexpr inline int const * ip = nullptr ;
static_assert(probe(ip));
But here is the, compile time no-can-do area:
// deliberately omitted constexpr
inline const char * wot_here_ = "Another literal";
// error: the value of 'wot_here_' is not usable in a
// constant expression
// note: 'wot_here_' was not declared 'constexpr'
// static_assert(probe(wot_here_));
I understand wot_here_
is the runtime variable. probe()
is declared and implemented with argument types only. Am I openly going against some obvious rule in the standard? Or subtly, against a few subtle ones.
I am cautiously hoping someone can sort of, "get around" this issue?