Search code examples
c++templatesdependent-name

Is there an equivalent of "typename" for template types?


We have a template member function of the form:

template <template <class> class TT>
TT<some_type> foo() const;

Now, in an invocation context where TT is explicitly specified from a dependent name:

template <class T_other>
void bar()
{
    instance.foo<T_other::template_type>();
}

Visual Studio is able to compile the invocation. GCC complains:

error: dependent-name ‘SomeConcreteType::template_type’ is parsed as a non-type, but instantiation yields a type.

And advises to say typename SomeConcreteType::template_type. Which does not work, since SomeConcreteType::template_type is a template type, not a plain type.

  • Is there a keyword that can be used here?
  • Another way to make this accepted by the big 3 compilers?

EDIT: Now with a Godbolt minimal example https://godbolt.org/z/hvbb6jv9W


Solution

  • Use template instead of typename. And, note that while typename would go before the ::, template goes after.

    template<class T_other>
    void bar() {
        instance.foo<T_other::template template_type>();
    }
    

    Complete example.