In C++20 or later, how to pack the const references of constexpr objects in template parameter list to an array? Something like following code, noticing the ...
is not in foo()
but only in template <>
.
using Key = std::string_view;
template <const Key & ... KS>
consteval auto foo()
{
return std::to_array<Key>(KS ...); // compile error
}
constexpr inline Key k1 = "abc";
constexpr inline Key k2 = "xyz";
auto a = foo<k1, k2>;
Is there something like std::forward_as_tuple
I can use? Perhaps something called forward_as_array
.
1