栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

c++-模板元编程 编译期归并排序

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c++-模板元编程 编译期归并排序

前置内容
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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/384954.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号