1

Since C++20, we have deduction guides (CTAD) for alias templates. THIS post explains the concept pretty well. My question is: Why does the deduction fail for FooAlias in the following piece of code (godbolt)?

template <class T>
struct Foo {
    Foo(T) {}
};

template <class T>
struct Selector {
    using type = T;
};

template <class T>
using FooAlias = Foo<typename Selector<T>::type>;

void test(){
    Foo f1{3.0}; // Compiles
    FooAlias f2{3.0}; // Error, class template argument deduction failed
}

The line with f2 fails to compile on both MSVC19.30 and gcc11 (clang13 does not yet support deduction for alias templates).

My guess is that typename Selector<T>::type in the definition of FooAlias is not a "simple-template-id". But I failed to comprehend the standard here. Specifically, if I try to follow the standard, a "simple-template-id" can contain multiple "template-arguments", where each of them can be an "id-expression", which can be a "qualified-id", which can be of the form "simple-template-id::unqualified-id". And to me, Selector<T>::type looks to satisfy this. What am I missing?

Sedenion
  • 5,421
  • 2
  • 14
  • 42

0 Answers0