变换元组类型 [英] Transform tuple type
问题描述
所以,我是新来提振MPL,我不知道如何与标准型使用。
我想这覆羽这种类型的元函数:
的std ::元组LT; T0,T1,...,TN>
进入这个:
的std ::元组LT;
的std ::功能< T0(的std ::元组LT; T0,T1,...>中的std ::元组LT; T0,T1,...>)>中
的std ::功能< T1(的std ::元组LT; T0,T1,...>中的std ::元组LT; T0,T1,...>)>中
...
的std ::功能< TN(...)>
>
和它看起来像这可能是与的变换,但我希望有一个元组类型,而不是一个类型的载体。 (它没有实际使用MPL,但我想它会更短?)
背景:目前我使用完全泛型类型,依靠所有的地狱,如果用错了破散,但我要计算 TupleOfFunctions
来得到一个正确的错误
模板<类TupleOfValues,类TupleOfFunctions>
无效F(TupleOfValues V,TupleOfFunctions乐趣)
如何下?
模板< typename的T>结构变换;
模板< typename的... T>
结构转型与LT;的std ::元组<吨...>> {
的typedef的std ::元组LT;的std ::功能< T,的std ::元组<吨...>中的std ::元组<吨...>> ...>类型;
};
So I'm new to boost MPL, and I don't know how to use it with standard types.
I want a metafunction that coverts this type:
std::tuple<T0, T1, ..., TN>
Into this:
std::tuple<
std::function<T0(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
std::function<T1(std::tuple<T0, T1, ...>, std::tuple<T0, T1, ...>)>,
...,
std::function<TN(...)>
>
and it seems like this could be done with transform, but I want to have a tuple-type, not a vector of types. (It doesn't have to use MPL actually, but I guess it would be shorter?)
Background: currently I use totally generic types and rely on all hell breaking loose if used wrong, but I want to calculate the TupleOfFunctions
to get a proper error.
template<class TupleOfValues, class TupleOfFunctions>
void f(TupleOfValues v, TupleOfFunctions fun)
How about the following?
template<typename T> struct transform;
template<typename ...T>
struct transform<std::tuple<T...>> {
typedef std::tuple<std::function<T, std::tuple<T...>, std::tuple<T...>>...> type;
};
这篇关于变换元组类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!