template<int...>
struct S {};
constexpr auto a = std::array{0, 1, 2};
我想将元素
a
作为模板参数传递给S
,即:S<0, 1, 2>
。以下是可能的C++2a实现:
template<auto tuple_like, template<auto...> typename Template>
constexpr decltype(auto) unpack()
{
constexpr auto size = std::tuple_size_v<decltype(tuple_like)>;
return []<std::size_t... Is>(std::index_sequence<Is...>) {
return Template<std::get<Is>(tuple_like)...>{};
}(std::make_index_sequence<size>{});
}
using Result = decltype(unpack<a, S>());
Boost.Hana 中有没有惯用的方法可以做到这一点?