Is it possible to transform the types in a parameter pack?

本小妞迷上赌 提交于 2019-12-30 03:58:23

问题


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

E.g. given the following:

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

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, ":(");

回答1:


Yes we can do that

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


来源:https://stackoverflow.com/questions/3273504/is-it-possible-to-transform-the-types-in-a-parameter-pack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!