是否可以转换参数包中的类型? [英] Is it possible to transform the types in a parameter pack?

查看:124
本文介绍了是否可以转换参数包中的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以转换参数包的类型并将其传递?

Is it possible to transform the types of a parameter pack and pass it on?

例如。给定以下内容:

template<class... Args> struct X {};
template<class T> struct make_pointer     { typedef T* type; };
template<class T> struct make_pointer<T*> { typedef T* type; };

我们可以定义一个模板 magic 类似,以便以下断言成立:

Can we define a template magic or something similar so that the following assertion holds:

typedef magic<X, make_pointer, int, char>::type A;
typedef X<int*, char*> B;
static_assert(is_same<A, B>::value, ":(");


推荐答案

是的,我们可以做

template<template<typename...> class List, 
         template<typename> class Mod, 
         typename ...Args>
struct magic {
    typedef List<typename Mod<Args>::type...> type;
};

这篇关于是否可以转换参数包中的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆