This topic has not yet been rated - Rate this topic

unordered_map::emplace_hint

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

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

Parameter

Description

ValTy

The in-place constructor argument type.

val

Value to insert.

where

Where in container to insert (hint only).

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

Header: <unordered_map>

Namespace: std

Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.