Is it possible to transform the types in a parameter pack?
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;
};
精彩评论