views:

86

answers:

1

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

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;
};
Johannes Schaub - litb
Ah, *§14.5.3/5* even includes examples which i somehow managed to overlook :)
Georg Fritzsche