According to my previous question's answer,
std::pair<iterator, bool> std::unordered_map::insert(const value_type&)
is useful than
template<class P>
std::pair<iterator, bool> std::unordered_map::insert(P&&)
for some situations like
std::unordered_map<std::string, int> v;
v.insert({"key", 1});
because the compiler cannot deduce P
from {"key", 1}
. (Thanks sellibitze)
However, although this argument {"key", 1}
(= std::pair<std::string, int>("key", 1)
) is prvalue, it cannot move to the container because the argument type is const value_type&
.
My question is --- I am sorry to be persistent --- why the standard choose const value_type&
for the argument type instead of value_type&&
? Or, are there any other reasons that the function with an argument type const value_type&
exists and the function with an argument type value_type&&
does not exist?
Edit: I created a sample.
- With an argument type
const value_type&
like unordered_map: http://ideone.com/GB72fc. - With an argument type
value_type&&
only: http://ideone.com/dXnQJr. - With both argument types: http://ideone.com/shAb9e.