Share via


unordered_map::emplace_hint

Adds an element constructed in place, with a placement hint.

template<class ValTy>
    iterator emplace(const_iterator where, ValTy&& val);

Parameters

Parameter

Description

ValTy

The in-place constructor argument type.

val

Value to insert.

where

Where in container to insert (hint only).

Remarks

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.

Example

// 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

Requirements

Header: <unordered_map>

Namespace: std

See Also

Reference

<unordered_map>

unordered_map Class

Other Resources

<unordered_map> Members