mardi 10 octobre 2017

Specifying a default template

Consider this:

template <typename Pack, template <typename...> class = std::tuple> struct foo;

template <template <typename...> class P, typename... Ts, template <typename...> class Q>
struct foo<P<Ts...>, Q> {
    using type = Q<P<Ts>...>;   
};

I've placed the default template in the typedef to be std::tuple to make this compile, but what I actually want is the default template to be P, and I don't know of any syntax that allows this. I kept the typedef simple to illustrate the point, which is trying to get P as the default template. So I came up with the following workaround that seems kind of ugly:

template <typename Pack, template <typename...> class...> struct foo;

template <template <typename...> class P, typename... Ts, template <typename...> class Q>
struct foo<P<Ts...>, Q> {
    using type = Q<P<Ts>...>;   
};

template <template <typename...> class P, typename... Ts>
struct foo<P<Ts...>> {
    using type = P<P<Ts>...>;   
};

Is there any better way to do it than this? Perhaps some c++17 syntax that I'm not aware of?

Aucun commentaire:

Enregistrer un commentaire