Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of "typename", to indicate that a dependant name is indeed a 'template template parameter'

We reduced a portion of code we cannot find the right syntax for to a minimal example.

Let's assume the following definitions (worry not about the "why" ;)

template <class>
class Element
{};

template <template <class> class>
class Client
{};

template <class>
struct TemplatedProvider
{
    template <class T>
    using element_template = Element<T>;
};

Now, with C++11 onward, we can use either a class template or a type alias template to instantiate the Client template. The following function compiles just fine:

void fun()
{
    Client<Provider::element_template> client;
    Client<TemplatedProvider<int>::element_template> clientBis;
}

But we cannot find the proper syntax in the following case, when the template argument given to Client is a dependent name:

template <class T>
void templatedFun()
{
    Client<TemplatedProvider<T>::element_template> client;
}

Clang (tested with 3.6) is emitting the following compilation error:

template argument for template template parameter must be a class template or type alias template

Can we fix this syntax ?

like image 632
Ad N Avatar asked Dec 11 '22 20:12

Ad N


1 Answers

It has to be:

template <class T>
void templatedFun()
{
    Client<TemplatedProvider<T>::template element_template> client;
}
like image 60
m.s. Avatar answered Dec 13 '22 11:12

m.s.