前置课程 c++模板元编程TypeList定义及基本操作
#include "def.h"
template<typename List, template<class, class> typename MetaFunc, typename Init, bool = IsEmpty_v<List>>
struct Accumulate_;
template<typename List, template<class, class> typename MetaFunc, typename Init>
struct Accumulate_<List, MetaFunc, Init, true> {
using type = Init;
};
template<typename List, template<class, class> typename MetaFunc, typename Init>
struct Accumulate_<List,MetaFunc,Init, false>
: public Accumulate_<
PopFront_t<List>,
MetaFunc,
typename MetaFunc<Init, Front_t<List>>::type> {};
template<typename List, template<class, class> typename MetaFunc, typename Init>
using Accumulate_t = typename Accumulate_<List, MetaFunc, Init>::type;
template<typename Source, typename Des = TypeList<>>
struct Reverse_Acc_ {
using type = Accumulate_t<Source, PushFront_, Des>;
};
template<typename Source, typename Des = TypeList<>>
using Reverse_Acc_t = typename Reverse_Acc_<Source, Des>::type;
template<typename T>
struct Identity {
using type = T;
};
template<typename Init, typename Current>
struct BiggerType_ {
using type = typename conditional_t<sizeof(Init) >=sizeof(Current), Identity<Init>, Identity<Current>>::type;
};
template<typename Init, typename Current>
using BiggerType_t = typename BiggerType_<Init, Current>::type;
template<typename Source, typename Des = char>
struct BiggestType_{
using type = Accumulate_t<Source, BiggerType_, Des>;
};
template<typename Source, typename Des = char>
using BiggestType_t = typename BiggestType_<Source, Des>::type;
struct Big {
char buffer[1024];
};
int main() {
using SL = TypeList<Big, int, char, long long>;
using Reverse_SL = Reverse_Acc_t<SL>;
cout << boost::typeindex::type_id_with_cvr<Reverse_SL>().pretty_name()<< endl;
using Biggest_SL = BiggestType_t<SL>;
cout << boost::typeindex::type_id_with_cvr<Biggest_SL>().pretty_name()<< endl;
}
|