That's a less-known feature of C++, as @jrok pointed out blazingly fast, Koenig Lookup, or in modern C++ 1), ADL (Argument-Dependent Lookup). What it does is basically searches in the namespaces of the arguments for the function that you want to call (make_pair
in this example). The argument triggering the ADL is obviously std::pair
.
1)the naming has been changed, though a lot of people know the first term
Perhaps it's worth mentioning that ADL is quite important for one particular type of function: operators. If not for ADL, it would be impossible for even the trivial C++ "hello, world!" to work, because this:
std::cout << "Hello, world!";
Would have to be written as this:
std::operator<< (std::cout, "Hello, world!");
Thanks to ADL, <<
is properly resolved to be in std
namespace.
References:
- Wikipedia Article
- Great video by Stephan T. Lavavej, Core C++ Part 1
- A broader look on ADL and its uses by Herb Sutter
- It can be found in The C++ Standard (I was using n3485 version) in § 3.4.2