I saw the following code:
template<class T, T t = T()>
class A {
t > T()
};
I am confused about the second template parameter( t = T() ). Is that a function returning T or a non-type parameter? And what does it mean by comparing t and T()?
I saw the following code:
template<class T, T t = T()>
class A {
t > T()
};
I am confused about the second template parameter( t = T() ). Is that a function returning T or a non-type parameter? And what does it mean by comparing t and T()?
The second argument is a non-type parameter but it is not a function.
T t = T()
simply specifies a default value of the template parameter t
.
You can create instances of the template using:
A<int> a1; // Equivalent to A<int, 0>
A<int, 10> a2;
A<bool> a3; // Equivalent to A<bool, false>
A<bool, true> a4;
The line
t > T()
does not make sense at all.