How do default template arguments work?

I know that there are many questions asked about the syntax of the default arguments of the template.

Usually the answer (according to my understanding of how it should work) is to use something like this:

template <class T = SomeDefault> class T1 {};

Recently, I wanted to check which implementation option Boost uses in its own mapped_vector. And found the following snippet:

template<class T, class A>
class mapped_vector:

There seems to be Ano default binding for the argument , but apparently I can instantiate mapped_vector<int>just fine. Obviosuly the default argument is somehow deduced, but how?

edit: To be precise, I'm talking about line 279 in this file

+4
source share
1

( @Xeo) . . . a , .

: (Boost )

template<typename T = int> class A;
template<typename T> class A {};

:

template<typename T = bool> class A;
template<typename T = int> class A {};

:

template<typename T = int> class A;
template<typename T = int> class A {};

, . :

template<typename T> class A;
template<typename T = int> class A {};

, . , , , :

template<class T, class U = bool> class A;
template<class T = int, class U> class A {};

... , . : ( - - @Xeo)

template<class T, class U, class V = double> class A;
template<class T, class U = bool, class V> class A;
template<class T = int, class U, class V> class A {};

, , . :

template<typename T = int> class A {};
+6

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


All Articles