2010-05-29 4 views
1

메타 - 벡터와 가변적 인 템플릿 인자를 splat하기위한 기존의 함수 (boost mpl 또는 fusion)가 있습니까? 예 :C++ 메타 - 스 플랫 함수

splat<vector<T1, T2, ...>, function>::type 
// that would be the same as 
function<T1, T2, ...> 

내 검색에서 찾지 못했지만 이미 존재하는 경우 재발행하고 싶지 않습니다. F 주어

apply(f, t); 
// that would be the same as 
f(t[0], t[1], ...); 

융합 서열 일부 템플릿 기능 이다 :

대안으로,에 대한 솔루션이 존재한다.

편집 : 일부 검색 후 나는 당신이 N 귀하의 템플릿을 취 템플릿 인수의 수는 unpack_argsquoteN가 필요

+0

여기'vector'는 모든 템플릿 일 수 있습니까? – kennytm

+0

@Ken mpl 또는 융합 호환 시퀀스 – Anycorn

답변

1

http://www.boost.org/doc/libs/1_43_0/libs/fusion/doc/html/fusion/functional/invocation/functions.html에서 발견했다. 또는 메타 함수 클래스로 function을 구현하면 quoteN이 필요하지 않습니다. 주어진 두 종류의 첫 번째 항복 metafunction 클래스의 예 :

struct function1st { 
    template<typename T1, typename T2> 
    struct apply { typedef T1 type; }; 
}; 

/* create a metafunction class that takes a sequence and apply it to function1st */ 
typedef unpack_args<function1st> unpacker; 

그런 다음 당신은 당신이 템플릿으로있는 경우 순서를

BOOST_MPL_ASSERT((is_same< apply<unpacker, vector<int, char> >::type, int>)); 

소요 아니면 metafunction 클래스로 당신을 unpacker을 사용할 수 있습니다 먼저 인용해야합니다.

template<typename T1, typename T2> 
struct function1st { typedef T1 type; }; 

/* create a metafunction class that takes a sequence and apply it to function1st */ 
typedef unpack_args< quote2<function1st> > unpacker; 

희망이 있습니다.

+0

고마워요. 불행히도 매개 변수의 수가 가변적이어서 함수 구현을 제어하지 않기 때문에 두 방법 모두 구현하기가 다소 어렵습니다. 그러나 그것을 해결할 다른 방법이 있습니다. 하지만 나는 계속해서 마음을 풀고 견적을 남긴다. 그들은 나를 위해 매우 유용 할 것이다. – Anycorn

+1

내 문제를 해결하는 mpl 호출의 구조를 보았다. http://www.boost.org/doc/libs/ 1_43_0/libs/fusion/doc/html/fusion/functional/invocation/functions.html – Anycorn