c++-模板元编程TypeList进阶操作 transform

前置课程
c++模板元编程TypeList定义及基本操作

#include "def.h"
// def.h 源码
// https://blog.csdn.net/qq_34179431/article/details/120977389

// ************************ transform

template<typename List, template<class> typename MetaFunc, bool = IsEmpty_v<List>>
struct Transform_;

// 通用型
template<typename List, template<class> typename MetaFunc>
struct Transform_<List, MetaFunc, false> {
 private:
    using Front = Front_t<List>;
    using Tail = typename Transform_<PopFront_t<List>, MetaFunc>::type;
 public:
    using type = PushFront_t<Tail, typename MetaFunc<Front>::type>;
};

template<typename List, template<class> typename MetaFunc>
struct Transform_<List, MetaFunc, true> {
    using type = List;
};

// 特化版
template<template<class ...name> typename List, template<class> typename MetaFunc,  typename ...Types>
struct Transform_<List<Types...>, MetaFunc, false> {
    using type = List<typename MetaFunc<Types>::type...>;
};

template<template<class ...name> typename List, template<class> typename MetaFunc>
struct Transform_<List<>, MetaFunc, true> {
    using type = List<>;
};

template<typename List, template<class> typename MetaFunc>
using Transform_t = typename Transform_<List, MetaFunc>::type;

// 实践一
// 给每个类型增加 const
template<typename List>
struct AddConstToAll_ {
    using type = Transform_<List, add_const>;
};

template<typename List>
using AddConstToAll_t =  typename Transform_<List, add_const>::type;



int main() {
    using SL = TypeList<int, char, long>;
    using SSL = AddConstToAll_t<SL>;
    cout << boost::typeindex::type_id_with_cvr<SSL>().pretty_name() << endl;
}

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值