It calls the two argument constructor of pair
which then calls the single argument constructors of each specific type.
The compiler will choose a constructor with an initialization list if:
- It has a constructor with an initialization list
- It fits the requirements of an initialization list (All elements are of same type)
std::pair does not satisfy either requirement so it finds a constructor with matching argument types.
This is the constructor it calls for pair
from stl_pair.h
(gcc 11.2)
explicit constexpr pair(const _T1& __a, const _T2& __b)
: first(__a), second(__b) { }
Since C++17 You can use the following statement too:
std::pair p = {1,"text"};
One thing I would point out is that you are using copy list initialization because of the equal sign rather than direct initialization. This can have some side effects but probably won't.
Good reading here:Constructors and member initializer lists