unordered_map::emplace_hint
Visual Studio 2010
Adds an element constructed in place, with a placement hint.
template<class ValTy>
iterator emplace(const_iterator where, ValTy&& val);
The member function returns insert(move(val)).first, using where as a starting place within the controlled sequence to search for the insertion point. (Insertion can possibly occur somewhat faster, if the insertion point immediately precedes or follows where.)
If an exception is thrown during the insertion, the container is left unaltered and the exception is rethrown.
// std_tr1__unordered_map__unordered_map_emplace_hint.cpp
// compile with: /EHsc
#include <unordered_map>
#include <iostream>
#include <string>
typedef std::unordered_map<char, int> Mymap;
int main()
{
using namespace std;
unordered_multimap<int, string> c1;
pair<int, string> is1(1, "a");
c1.emplace(move(is1));
cout << "After the emplace insertion, c1 contains:" << endl
<< " " << c1.begin()->first
<< " => " << c1.begin()->second
<< endl;
return (0);
}
After the emplace insertion, c1 contains: 1 => a