[map.modifiers] (original) (raw)

23 Containers library [containers]

23.4 Associative containers [associative]

23.4.3 Class template map [map]

23.4.3.4 Modifiers [map.modifiers]

template<class P> constexpr pair<iterator, bool> insert(P&& x);template<class P> constexpr iterator insert(const_iterator position, P&& x);

Constraints: is_constructible_v<value_type, P&&> is true.

Effects: The first form is equivalent toreturn emplace(std​::​forward<P>(x)).

The second form is equivalent to return emplace_hint(position, std​::​forward<P>(x)).

template<class... Args> constexpr pair<iterator, bool> try_emplace(const key_type& k, Args&&... args);template<class... Args> constexpr iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args);

Preconditions: value_type is Cpp17EmplaceConstructible into mapfrom piecewise_construct, forward_as_tuple(k),forward_as_tuple(std​::​forward<Args>(args)...).

Effects: If the map already contains an element whose key is equivalent to k, there is no effect.

Otherwise inserts an object of type value_typeconstructed with piecewise_construct, forward_as_tuple(k),forward_as_tuple(std​::​forward<Args>(args)...).

Returns: In the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.

template<class... Args> constexpr pair<iterator, bool> try_emplace(key_type&& k, Args&&... args);template<class... Args> constexpr iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args);

Preconditions: value_type is Cpp17EmplaceConstructible into mapfrom piecewise_construct, forward_as_tuple(std​::​move(k)),forward_as_tuple(std​::​forward<Args>(args)...).

Effects: If the map already contains an element whose key is equivalent to k, there is no effect.

Otherwise inserts an object of type value_typeconstructed with piecewise_construct, forward_as_tuple(std​::​move(k)),forward_as_tuple(std​::​forward<Args>(args)...).

Returns: In the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.

template<class K, class... Args> constexpr pair<iterator, bool> try_emplace(K&& k, Args&&... args);template<class K, class... Args> constexpr iterator try_emplace(const_iterator hint, K&& k, Args&&... args);

Constraints: The qualified-id Compare​::​is_transparentis valid and denotes a type.

For the first overload,is_convertible_v<K&&, const_iterator> andis_convertible_v<K&&, iterator>are both false.

Preconditions: value_type is Cpp17EmplaceConstructible into map frompiecewise_construct, forward_as_tuple(std​::​forward<K>(k)), forward_as_tuple(std​::​forward<Args>(args)...).

Effects: If the map already contains an element whose key is equivalent to k, there is no effect.

Otherwise, let r be equal_range(k).

Constructs an object u of type value_type withpiecewise_construct, forward_as_tuple(std​::​forward<K>(k)), forward_as_tuple(std​::​forward<Args>(args)...).

If equal_range(u.first) == r is false, the behavior is undefined.

Inserts u into *this.

Returns: For the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.

template<class M> constexpr pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj);template<class M> constexpr iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj);

Mandates: is_assignable_v<mapped_type&, M&&> is true.

Preconditions: value_type is Cpp17EmplaceConstructible into mapfrom k, std​::​forward<M>(obj).

Effects: If the map already contains an element ewhose key is equivalent to k, assigns std​::​forward<M>(obj) to e.second.

Otherwise inserts an object of type value_typeconstructed with k, std​::​forward<M>(obj).

Returns: In the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.

template<class M> constexpr pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj);template<class M> constexpr iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj);

Mandates: is_assignable_v<mapped_type&, M&&> is true.

Preconditions: value_type is Cpp17EmplaceConstructible into mapfrom std​::​move(k), std​::​forward<M>(obj).

Effects: If the map already contains an element ewhose key is equivalent to k, assigns std​::​forward<M>(obj) to e.second.

Otherwise inserts an object of type value_typeconstructed with std​::​​move(k), std​::​forward<M>(obj).

Returns: In the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.

template<class K, class M> constexpr pair<iterator, bool> insert_or_assign(K&& k, M&& obj);template<class K, class M> constexpr iterator insert_or_assign(const_iterator hint, K&& k, M&& obj);

Constraints: The qualified-id Compare​::​is_transparentis valid and denotes a type.

Mandates: is_assignable_v<mapped_type&, M&&> is true.

Preconditions: value_type is Cpp17EmplaceConstructible into map fromstd​::​forward<K>(k), std​::​
forward<M>(obj).

Effects: If the map already contains an element ewhose key is equivalent to k, assigns std​::​forward<M>
(obj) to e.second.

Otherwise, let r be equal_range(k).

Constructs an object u of type value_typewith std​::​forward<K>(k), std​::​forward<M>(obj).

If equal_range(u.first) == r is false, the behavior is undefined.

Inserts u into *this.

Returns: For the first overload, the bool component of the returned pair is trueif and only if the insertion took place.

The returned iterator points to the map element whose key is equivalent to k.

Complexity: The same as emplace and emplace_hint, respectively.