前置内容
c++模板元编程ValueList定义及基本 *** 作
#include#include #include #include #include "valueList.h" using namespace std; template > struct EmptyList_ : public EmptyList_ > { }; template using EmptyList_t = typename EmptyList_ ::type; template
struct EmptyList_ { using type = List; }; template
struct PushBackOneSortedList_ : public PushBackOneSortedList_< PushBack_t< ResultList, NthElem_t >, List, Begin + 1, End > { }; template
using PushBackOneSortedList_t = typename PushBackOneSortedList_ ::type; template struct PushBackOneSortedList_ { using type = ResultList; }; template typename Compare, bool = (LBegin + 1 <= LEnd), bool = (RBegin + 1 <= REnd)> struct MergeSortedList_ { constexpr static auto b = Compare , NthElem_t >::value; using TailOne = typename conditional_t>, Identity > >::type; constexpr static auto LBegin1 = b ? LBegin + 1 : LBegin; constexpr static auto RBegin1 = b ? RBegin : RBegin + 1; using RR = PushBack_t ; using type = typename MergeSortedList_ ::type; }; template typename Compare> using MergeSortedList_t = typename MergeSortedList_ ::type; template typename Compare> struct MergeSortedList_ { // 两个列表都为空 using type = ResultList; }; template typename Compare> struct MergeSortedList_ { // 右侧列表为空 using type = typename PushBackOneSortedList_ ::type; }; template typename Compare> struct MergeSortedList_ { // 左侧列表为空 using type = PushBackOneSortedList_t ; }; template struct NthElem_ , 0, true> { using type = CTValue_ ; }; template typename Compare, unsigned Begin, unsigned End, bool = (Begin + 1 == End), bool = (Begin < End)> //false, true struct DivideAndConquerSortHelper_ { constexpr static auto Mid = (Begin + End - 1) / 2; using EmptyType = EmptyList_t ; using Left = typename DivideAndConquerSortHelper_
::type; using Right = typename DivideAndConquerSortHelper_
::type; using type = MergeSortedList_t
, 0, ListSize_v , EmptyType, Compare>; }; template typename Compare, unsigned Begin, unsigned End> struct DivideAndConquerSortHelper_ { using EmptyType = EmptyList_t
; using type = PushFront_t
>; }; template typename Compare, unsigned Begin, unsigned End> struct DivideAndConquerSortHelper_ { using type = EmptyList_t
; }; template
typename Compare, bool = IsEmpty_v || IsEmpty_v
>> struct DivideAndConquerSort_ { using type = typename DivideAndConquerSortHelper_ >::type; }; template
typename Compare> struct DivideAndConquerSort_ { using type = List; }; template
struct Obj { char buffer[N]; }; //#ifdef DIVIDE int main() { using SL = TypeList , Obj<1024>,char, Obj<16>, long, Obj<24>, short, Obj<512>>; // LessBigger 按照类型大小排序 using Sorted_SL = typename DivideAndConquerSort_ ::type; cout << boost::typeindex::type_id_with_cvr ().pretty_name() << endl; } //#endif
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)