C++11 TypeList ????
???????????? ???????[ 2015/3/4 15:14:09 ] ????????C++ ???????
?????????:
#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;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11