This documentation is archived and is not being maintained.


Adds an element constructed in place.

template<class ValTy>
    pair<iterator, bool> emplace(ValTy&& val);




The in-place constructor argument type.


Value to insert.

The member function determines whether an element X exists in the sequence whose key has equivalent ordering to that of val. If not, it constructs such an element X with val. The function then determines the iterator where that designates X. If an insertion occurred, the function returns std::pair(where, true). Otherwise, it returns std::pair(where, false).

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.cpp 
// compile with: /EHsc 
#include <unordered_map> 
#include <iostream> 
#include <string>
int main() 
    using namespace std;
    unordered_map<int, string> c1;
    pair<int, string> is1(1, "a");

    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

Header: <unordered_map>

Namespace: std