vendredi 3 mai 2019

template specialization and alias deduction difference

I'm struggling to understand how deduction works in the following case:

template<class Category, Category code>
  struct AImpl
  { };

  template<class Category, Category code>
  struct AHelper
    {
    using type = AImpl<Category, code>;
    };

  template<class Category, Category code>
  using A = typename AHelper<Category, code>::type;

template<int code>
void doSomething(A<int, code> object)

{
}

Following is the test code:

A<int, 5> a1;
doSomething(a1); // This does not compiles

A<int, 5> a2;
doSomething<5>; // This compiles

Why a1 is not deduced in this context?

If you modify A in the following way instead:

template<class Category, Category code>
  struct A
  { };

Both work. Anyone knows why?

Aucun commentaire:

Enregistrer un commentaire