Search code examples
c++c++11templatesusingtemplate-templates

How can a type alias with using specify a template template argument dependent on a template argument?


Minimal example:

template<template<class ...> class>
struct templ {};

template<class T>
using special = templ<T::type>;

int main() {}

clang++:

test.cpp:5:23: error: template argument for template template parameter must be a class template or type alias template
using special = templ<T::type>;

Indeed, I mean to say that T::type is a class template, e.g.

struct detail1 {
    template <class T>
    using type = std::vector<T>;
};

struct detail2 {
    template <class T>
    struct type {};
};

But how can one say this? g++ suggests to use typename T::type, but this seams wrong to me, and indeed, this does not solve the error.


Solution

  • You need to specify that type is a template:

    template<class T>
    using special = templ< T::template type>;
    

    This is needed because T::type is dependent on the template parameter T.

    See also Where and why do I have to put the “template” and “typename” keywords?