从 hana::tuple_t 到 hana::tuple

Aco*_*orn 5 c++ typelist boost-hana

我有一个hana::tuple_t<int, char, double, float>,我想用它来创建一个hana::tuple<int, char, double, float>.

我认为使用hana::to<hana::tuple_tag>会将hana::tuple_t<int, char, double, float>变成hana::tuple<int, char, double, float>; 但事实并非如此,因为以下总是失败:

auto oType = hana::tuple_t<int, char, double, float>;

BOOST_HANA_CONSTANT_ASSERT(
    hana::to<hana::tuple_tag>(oType)
    ==
    hana::make_tuple(1, 'C', 1.0, 1.0f)
);
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用hana::transform,但没有运气(尽管我怀疑我做错了):

auto vecs = hana::transform(typeList, [](auto t) {
    return typename decltype(t)::type{};
});
Run Code Online (Sandbox Code Playgroud)

那么,我该如何将 hana::tuple_t 转换为 hana::tuple 呢?

Lou*_*nne 4

我相信你真正想要的是这样的

#include <boost/hana.hpp>
namespace hana = boost::hana;

constexpr auto types = hana::tuple_t<int, char, double, float>;
using Tuple = decltype(hana::unpack(types, hana::template_<hana::tuple>))::type;
// Tuple is hana::tuple<int, char, double, float>
// Now you can create such a tuple as you wish:
Tuple ts{1, 'x', 2.2, 3.4f};
Run Code Online (Sandbox Code Playgroud)

hana::template_像和 之类的东西hana::metafunction正是为了使与类型的互操作变得容易而构建的。