繁体   English   中英

可以使用Boost.Hana将std :: array解压缩到非类型模板参数包中吗?

[英]Can a std::array be unpacked into a non-type template parameter pack with Boost.Hana?

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中有惯用的方法吗?

我想自然的异构类型Boost.Hana方法是将std::array元素提升到hana::integral_constanthana::tuple ,并将类模板提升为一个元函数:

template<int...>
struct S {};

using namespace boost::hana::literals;
constexpr auto a = boost::hana::make_tuple(0_c, 1_c, 2_c);

template<template<auto...> typename Template>
constexpr auto lift_non_type_template = []<typename... Ts>(Ts...) {
    return boost::hana::type_c<Template<Ts::value...>>;
};

using Result = decltype(boost::hana::unpack(a, lift_non_type_template<S>))::type;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM