I am not going to do something like this in real code, just want to better understand std::make_pair()
. I have read cppreference, but I don't understand std::decay
well. I find this to be a bit confusing:
std::vector<std::pair<int*, int*>> vec;
int* a = new int(1);
int* b = new int(2);
vec.emplace_back(std::make_pair(a, b)); // Fine
vec.emplace_back(std::make_pair<int*, int*>(&*a, &*b)); // Fine
vec.emplace_back(std::make_pair<int*, int*>(a, b)); // Error
Why do the first two calls to std::make_pair()
work, but the last one gives an error?
GCC: cannot bind rvalue reference of type ‘int*&&’ to lvalue of type ‘int*’
Clang: no matching function for call to 'make_pair'
How does the last std::make_pair()
differ from the previous two?