开发者

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

开发者 https://www.devze.com 2023-01-07 13:32 出处:网络
Is it possi开发者_如何学JAVAble to transform the types of a parameter pack and pass it on? E.g. given the following:

Is it possi开发者_如何学JAVAble 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, ":(");


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;
};
0

精彩评论

暂无评论...
验证码 换一张
取 消