Wednesday, 15 January 2014

c++ - Expanding a parameter pack of templateclasses -



c++ - Expanding a parameter pack of template<class>classes -

suppose have template classes defined follows

template<template<class>class...> struct my_class; template<class> struct define_template{ template<class> class type; };

i need define alias template substitutes define_template::type my_class 3 classes this

template<class a, class b, class c> using my_alias = my_class< define_template<a>::template type, define_template<b>::template type, define_template<c>::template type>;

i can't work out syntax variadic template ideally this

template<class... t> using new_class = my_class<define_template<t>::template type...>;

which gives me error "parameter packs not expanded '...'

does know right synax?

from comments below compiles in clang, i'm using gcc 4.8.2 through cygwin.

i'm assuming it's bug in gcc i've done workaround now

// partially specializes template template<template<class, class>class tt, class t> struct templatebind{ template<class s> using type = tt<t, s>; }; // workaround template<template<template<class>class...>class a, template<class, class>class b, template<class>class... c> class workaround { template<class d, class... e> static auto get_type(d, e...) -> typename workaround<a, b, c..., templatebind<b, d>::template type>::template type<e...>; static auto get_type() ->a<c...>; public: template<class... t> using type = decltype(get_type(std::declval<t>()...)); }; // convinience alias template<template<template<class>class...>class originaltemplate, template<class, class>class substitution, class... types> using instatiatevariadictemplatetemplate = typename workaround<originaltemplate, substitution>::template type<types...>;

then can define wrapper define_template

// wrapper alias gets define_template in right form template<class a, class b> using my_wrapper = typename define_template<a>::template type<b>;

and instantiate follows

template<class... t> using my_alias = instatiatevariadictemplatetemplate<my_class, my_wrapper, t...>;

c++ templates c++11 variadic-templates template-templates

No comments:

Post a Comment