bsl::map::try_emplace

Try to emplace an element with key constructed from args.

Synopsis

Declared in <bslstl_map.h>

template<class... Args>
pair<map<KEY, VALUE, COMPARATOR, ALLOCATOR>::iterator, bool>
try_emplace(
    KEY const& key,
    Args&&... args);

Description

If a key equivalent to the specified key already exists in this map, return a pair containing an iterator referring to the existing item and false. Otherwise, insert into this map a newly-created entry constructed from key and the specified args, and return a pair containing an iterator referring to the newly-created entry and true. This method requires that the (template parameter) types KEY and VALUE are emplace-constructible from key and args respectively. For C++03, VALUE must also be copy-constructible.

Return Value

pair of iterator and whether a new element was inserted

Parameters

NameDescription
keykey for the element to emplace
argsconstructor arguments for the mapped value