In the code I've been writing recently, I've noticed a strange behaviour.
When I use make_pair
with the first argument being an std::pair
, make_pair
becomes "magically" available in the namespace (I don't have to use an std::
qualifier)
#include <iostream>
int main()
{
int i1 = 2; int i2 = 10; int i3 = 0;
// constructing a pair using std::make_pair, everything's okay
std::pair<int,int> key = std::make_pair(i1, i2);
// here, why is make_pair suddenly magically available without the
// std:: namespace qualifier?
// At the same time, using ::make_pair yields and error
// (make_pair has not declared...)
std::pair<std::pair<int,int>, int> mypair = make_pair(key, i3);
std::cout << mypair.first.first << "\n";
std::cout << mypair.first.second << "\n";
std::cout << mypair.second << "\n";
return 0;
}
The compiles just fine (with -Wall and -pedantic-errors
) and outputs:
2
10
0
Why is this happening? I've looked into cppreference and didn't find any hint of this behaviour being correct. Am I missing anything?
FYI, I'm using gcc 4.6.3