jeudi 29 octobre 2015

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 ?

Aucun commentaire:

Enregistrer un commentaire