源码展示:
#include <iostream>
using namespace std;
template <typename ... Args> struct typelist;
typedef typelist <int ,short ,double ,long ,float> defaultPolicys;
template <typename A, typename B> struct concat;
template <typename... A, typename... B>
struct concat<typelist<A...>, typelist<B...> >
{
typedef typelist<A..., B...> type;
};
template<typename T, typename... TList>
struct concat<typelist<TList...>, T >
{
typedef typelist<TList..., T> type;
};
template<typename T, typename... TList>
struct concat< T, typelist<TList...> >
{
typedef typelist<T, TList...>  type;
};
template <typename T ,int I, typename K= defaultPolicys> struct replace;
template <typename T, int I, typename H,typename ...Tail> struct replace<T,I,typelist<H,Tail...>>
{
typedef typename concat<H, typename replace<T, I-1, typelist<Tail...>>::type>::type type;
};
template <typename T,typename H,typename... Tail> struct replace<T,0,typelist<H,Tail...>>
{
typedef typelist<T,Tail...> type;
};
template <typename T ,int I> struct Custom
{
const static int index = I;
typedef T newType;
};
template <typename ...> struct CEO;
template <> struct CEO<>
{
typedef defaultPolicys myPolicys;
};
template <typename T> struct CEO<T>
{
typedef typename replace<typename T::newType,T::index>::type myPolicys;
};
//template <typename T,typename U> struct CEO<T,U>{ typedef typename replace<typename U::newType,U::index,typename CEO<T>::myPolicys>::type myPolicy;};
template <typename T,typename ... Tail> struct CEO<T,Tail...>
{
typedef typename replace<typename T::newType,T::index,typename CEO<Tail...>::myPolicys>::type myPolicys;
};
int main()
{
typedef typelist <int ,short ,double ,long ,float> five;
typedef typelist <int ,short ,string, char ,string> fives;
if(is_same<typename CEO<>::myPolicys,five>::value)cout<<"..."<<endl;
if(is_same< CEO< Custom<string,2>,Custom<char,3>,Custom<string,4> > ::myPolicys,fives>::value)cout<<"..."<<endl;
return 0;
}