Suppose I have a constexpr array (of known bound) of static storage duration:
constexpr T input[] = /* ... */;
And I have an output class template that needs a pack:
template<T...> struct output_template;
I want to instantiate output_template
like:
using output = output_template<input[0], input[1], ..., input[n-1]>;
One way to do this is:
template<size_t n, const T (&a)[n]>
struct make_output_template
{
template<size_t... i> static constexpr
output_template<a[i]...> f(std::index_sequence<i...>)
{ return {}; };
using type = decltype(f(std::make_index_sequence<n>()));
};
using output = make_output_template<std::extent_v<decltype(input)>, input>::type;
Is there a cleaner or simpler solution I am missing?
using output = decltype(deduce(input))::unpack<input>;
? Not much cleaner, though. – Guanoa
seems to be the hurdle (even with moreconstexpr
in appropriate places): coliru.stacked-crooked.com/a/2c196c6f2a82cbfb – Hammerlessconstexpr int f(int a) { constexpr int b = a; return b; } // ill-formed.
– Stereographyusing output = foo<input>;
as far as I can see. – Guanotemplate<auto V>
whereV
is a compile-time value and the type can be easily accessed withdecltype(V)
. When I asked Mike and Daveed (the authors of N3601) about it, it turns out they also already came up with the exact same idea and syntax and want to prepare an updated version of N3601 :) – Homerhomere