共用方式為


unordered_map::emplace

Inserts an element constructed in place (no copy or move operations are performed) into an unordered_map.

template<class... Args>
   pair<iterator, bool> emplace(
      Args&&... args);

Parameters

Parameter

Description

args

The arguments forwarded to construct an element to be inserted into the unordered_map unless it already contains an element whose value is equivalently ordered.

Return Value

A pair whose bool component returns true if an insertion was made and false if the unordered_map already contained an element whose key had an equivalent value in the ordering, and whose iterator component returns the address where a new element was inserted or where the element was already located.

To access the iterator component of a pair pr returned by this member function, use pr.first, and to dereference it, use *(pr.first). To access the bool component of a pair pr returned by this member function, use pr.second.

Remarks

No iterators or references are invalidated by this function.

During the insertion, if an exception is thrown but does not occur in the container's hash function, the container is not modified. If the exception is thrown in the hash function, the result is undefined.

For a code example, see map::emplace.

Requirements

Header: <unordered_map>

Namespace: std

See Also

Reference

<unordered_map>

unordered_map Class

Standard Template Library