2017-01-04 1 views
2

필자가 직접 작성한 라이트 mpl을 사용하고 있지만 더 강력해야합니다. 현재, 내가 부스트 : 하나 사용에서 찾고, 한 가지를 제외하고, 내가 필요한 모든 것을 갖고있는 것 같아요 : 나는 그 유형의 컨테이너에 하나 :: 튜플 내에서 유형을 변경할 수있는 방법이 표시되지 않습니다.hana :: tuple in std :: vector를 hana :: tuple 내 <type>으로 변환

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

는 부스트 :: 있습니까 :

예를 들어

이 내가 표준의 표준 : : 튜플에 해당 유형의 :: 벡터를 유형의 표준 : 튜플을 변환하기 위해 사용 된 것입니다 내가 바라 보는 이것의 하나 변형. 또는 내가 하나 :: 튜플 대신에 표준 : : 튜플 작동이 이상을 가져오고 그것을 변경해야합니까?

답변

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로 발생합니다.