It is possible to unpack a value template parameter pack of type char into a (compile time) string.
How does one acquire a string_view
into that string?
What I want to do:
int main()
{
constexpr auto s = stringify<'a', 'b', 'c'>();
constexpr std::string_view sv{ s.begin(), s.size() };
return 0;
}
Try:
template<char ... chars>
constexpr auto stringify()
{
std::array<char, sizeof...(chars)> array = { chars... };
return array;
}
Error:
15 : <source>:15:30: error: constexpr variable 'sv' must be initialized by a constant expression
constexpr std::string_view sv{ s.begin(), s.size() };
^~~~~~~~~~~~~~~~~~~~~~~~~
15 : <source>:15:30: note: pointer to subobject of 's' is not a constant expression
Is there a way to get a the behaviour in the main
function?