Templated class, whose argument must be another template class

Well, this is what I am trying to achieve. I have a structure like this:

template<typename...Ts> struct s
{
    template<int...Is> struct r
    {
        // whatever
    };
};

Now I would like to write another template structure:

template<typename r> struct q
{
    //
};

The template must take specializations struct r, and I would like to have access to the template arguments of this instance.

To make it clearer: I would like to write something like this:

using some_specialisation_of_q = q< s<T1,T2,T3>::r<5,6,7> >;
some_specialisation_of_q varname;

And I would like to have access to T1,T2,T3, 5,6,7(or any other template arguments passed to specialists sand r) in the definition q.

My first attempt was something like this:

template<template<typename...Ts> template<int...Is> typename R, typename= typename std::enable_if<std::is_same<R, s<Ts...>::r<Is...>>::value>::type>
struct q
{
    //
}

But, unfortunately, this leads to compiler errors.

How can this be achieved?

+4
source share
1

-, Ts... r . :

template<typename...Ts> struct s
{
    template<int...Is> struct r
    {
        using outer_type = s;
    };
};

template<class T, class = typename T::outer_type, class = T>
struct q;

template<template <int...> class R, class...Ts, int...Is>
struct q<R<Is...>, s<Ts...>, typename s<Ts...>::template r<Is...>>{
};
0

Source: https://habr.com/ru/post/1619232/


All Articles