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