c++boost-hanatypelist

Going from hana::tuple_t to hana::tuple


I have a hana::tuple_t<int, char, double, float>, and I want to use this to create a hana::tuple<int, char, double, float>.

I thought that using hana::to<hana::tuple_tag> would transform the hana::tuple_t<int, char, double, float> into a hana::tuple<int, char, double, float>; but that is not the case since the following always fails:

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)
);

I've also tried using hana::transform, but with no luck (although I suspect I'm doing it wrong):

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

So, how do I go about turning a hana::tuple_t into a hana::tuple?


Solution

  • I believe what you really want here is something like

    #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};
    

    Things like hana::template_ and hana::metafunction were built precisely to make this interoperation with types easy.