I've been using a lite mpl that I wrote myself, but I need it to be more robust. Currently, I am looking at using boost::hana, and it seems to have everything I need, with one exception: I don't see any way to change the types within the hana::tuple to a container of those types.
For example, this is what I was using to transform a std::tuple of types into a std::tuple of std::vectors of those types:
#include <vector>
#include <tuple>
template<typename... Ts>
struct Typelist{
};
// Declare List
template<class> class List;
// Specialize it, in order to drill down into the template parameters.
template<template<typename...Args> class t, typename ...Ts>
struct List<t<Ts...>> {
using type = std::tuple<std::vector<Ts>...>;
};
// Sample Typelist
struct A{};
struct B{};
struct C{};
using myStructs = Typelist<A,B,C>;
// And, the tuple of vectors:
List<myStructs>::type my_tuple;
// Proof
int main()
{
std::vector<A> &a_ref=std::get<0>(my_tuple);
std::vector<B> &b_ref=std::get<1>(my_tuple);
std::vector<C> &c_ref=std::get<2>(my_tuple);
return 0;
}
Is there a boost::hana variant of this that I am overlooking? Or do I need to bring this over and change it up to work with hana::tuple instead of std::tuple?
You can use
hana::transform
for this:This maps over the types in the
types
tuple and throws them intostd::vector
.