3.9 移除typelist中的某个元素
移除第一个匹配者:
template <class TList, class T> struct Erase;
template <class T> struct Erase<NullType, T>{
typedef NullType Result;
};
template<class T, calss Tail>
struct Erase<Typelist<T, Tail> T>{
typedef Tail Result;
};
template <class Head, class Tail, class T>
struct Erase<Typelist<Head, Tail>, T>{
typedef Typelist<Head,
typename Erase<Tail, T>::Result>
Result;
};
注意Erase<double, int>这样使用会导致编译错误。移除所有匹配者的实现如下:
template <class Tlist, class T>struct EraseAll;
template <class T> struct EraseAll<NullType, T>{
typedef NullType Result;
};
template <class T, class Tail>
struct EraseAll<Typelist<T, Tail>, T>{
typedef typname EraseAll<Tail, T>::Result Result;
};
template <class Head, class Tail, class T>
struct EraseAll<Typelist<Head, Tail>, T>{
typedef Typelist<Head,
typename EraseAll<Tail, T>::Result>
Result;
};
3.10 移除重复元素(略)
3.11 取代Typelist中的某个元素(略)
3.12 为Typelists局部更换次序(略)