2017-01-04 7 views
2

私は自分自身で作成したlite mplを使用していますが、もっと頑強にする必要があります。現在、boost :: hanaを使用していますが、必要なものがすべてあるようですが、1つ例外があります。hana :: tuple内の型をこれらの型のコンテナに変更する方法はありません。これらのタイプのhana :: tuple in std :: vectorをhana :: tuple内の<type>に変換します

たとえば、これは私がSTDを変換するために使用していたものです:: STDへの種類のタプル::のstd ::タプルベクトル:

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

ブーストがあります::私が見落としているこれの変種?またはこれを持って、std :: tupleの代わりにhana :: tupleを使うように変更する必要がありますか?

答えて

2

あなたはこのためにhana::transformを使用することができます。

auto types = hana::tuple_t<A,B,C>; 
auto vecs = hana::transform(types, [](auto t) { 
    return hana::type_c<std::vector<typename decltype(t)::type>>; 
});  

static_assert(vecs == 
       hana::tuple_t<std::vector<A>, std::vector<B>, std::vector<C>>, 
       "wat"); 

これはtypesタプルのタイプの上にマッピングし、std::vectorにそれらをスローします。

関連する問題