Can a template parameter be either int or unsigned long?

I have the following code:

#include <iostream>

template<size_t N>
class A
{
};

template<int N, typename T> class B;

template<int N>
class B<N, A<N>>
{
};

int main()
{
    B<3, A<3>> b;
    return 0;
}

Here it is Btemplated on int, but Aon size_t, which is unsigned longwith both compilers that I use.

1 ( ), , . 2 (, ), , , B , unsigned long - ​​ 3 unsigned long, A, B. : B, size_t ( A, int)), , . , 2 (, ).

+6
1

[temp.deduct.type]:

P , <i>, i , simple-template-id, .

A<N> N - int, , A size_t. # 1.

+4

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


All Articles