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.
value_type&&overload ofinsertwas likely an oversight, as withmake_unique.make_uniquewas deliberate too. Though I've no objection to it being in a future standard. For C++11 there were not enough people sufficiently expert inunique_ptrto answer questions like: what do you do with the custom deleter? With array types? And I was spread too thin to push it.