Partager via


unordered_set::emplace_hint

Adds an element constructed in place.

template<class ValTy>
    iterator emplace_hint(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 

Code

// std_tr1__unordered_set__unordered_set_emplace_hint.cpp 
// compile with: /EHsc 
#include <unordered_set> 
#include <iostream>
#include <string> 
 
    unordered_set< string> c1;
    string str1("a");

    c1.emplace_hint(c1.begin(), move(str1));
    cout << "After the emplace insertion, c1 contains: "
        << *c1.begin() << endl;
 
     return (0); 
    } 
 

Output

After the emplace insertion, c1 contains: a

Requirements

Header: <unordered_set>

Namespace: std

See Also

Reference

<unordered_set>

unordered_set Class

Other Resources

<unordered_set> Members