How so? aliases not found in the attribute

The question is simple: look at the code. Both static statements pass. I did not expect the second to pass. Is this a mistake or normal behavior?

#include <array>
#include <type_traits>

template <template <class...> class Temp, class Specialization>
struct IsSpecialization : std::false_type {};

template <template <class...> class Temp, class... Ts>
struct IsSpecialization<Temp, Temp<Ts...>> : std::true_type {};

template <class...Args>
struct A {};

template <class...Args>
using AT = A<Args...>;


int main() {
    static_assert(IsSpecialization<A, A<int>>{});
    static_assert(!IsSpecialization<AT, AT<int>>{});
}
+4
source share
2 answers

Temp output twice when you try to do partial specialization:

  • Alignment Tempwith AT. This trivially deduces Temphow AT.
  • Combining Temp<Ts...>with AT<int>. This outputs Temphow A, because it is AT<int>equivalent A<int>, and this output will never output an alias pattern (see [temp.alias] / 2 ).

- - Temp , iff AT A . .

+6

(. T.C. ), : IsSpecialization

template <template <typename...> class Temp1,
          template <typename...> class Temp2, typename... Ts>
struct IsSpecialization<Temp1, Temp2<Ts...>>
   : public std::is_same<Temp1<Ts...>, Temp2<Ts...>>
 { };

T.C. , AT AT, , A<Ts...> .

AT A -, (Ts...), AT<Ts...> A<Ts...>. AT<Ts...> A<Ts...> , std::is_same .

+2

Source: https://habr.com/ru/post/1691950/


All Articles