char 型の値テンプレート パラメーター パックを (コンパイル時の) 文字列にアンパックできます。その文字列にa をどのように取得string_view
しますか?
私がしたいこと:
int main()
{
constexpr auto s = stringify<'a', 'b', 'c'>();
constexpr std::string_view sv{ s.begin(), s.size() };
return 0;
}
試す:
template<char ... chars>
constexpr auto stringify()
{
std::array<char, sizeof...(chars)> array = { chars... };
return array;
}
エラー:
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
関数で動作を取得する方法はありmain
ますか?