I defined the following class, expecting to be able to use std::array
in a constexpr
context, but calling the data function results in a compilation error.
#include <array>
template <size_t N>
struct ConstexprString
{
consteval ConstexprString(const char (&_str)[N])
: char_array(std::to_array(_str))
{
}
consteval auto Data() const -> const char*
{
return char_array.data();
}
private:
const std::array<char, N> char_array;
};
Test code
constexpr sz::tp::detail::ConstexprString csexpr_str("123\\0");
constexpr auto d = csexpr_str.Data(); // error C2131: expression did not evaluate to a constant