object::insert_or_assign

## `object::insert_or_assign`

Insert an element or assign to an existing element.

### Synopsis

    template<
        class M>
    std::pair< object::iterator, bool >
    insert_or_assign(
        string_view key,
        M&& m);

### Description

If the key equal to `key` already exists in the container, assigns `std::forward<M>(m)` to the `mapped_type` corresponding to that key. Otherwise, inserts the as if by `insert`, constructing it using `value_type(key, std::forward<M>(m))`.

If insertion would result in the new number of elements exceeding `capacity()`, a reallocation and a rehashing occur. In that case all iterators and references are invalidated. Otherwise, they are not affected.

### Complexity

Constant on average, worst case linear in `size()`.

### Exception Safety

Strong guarantee. Calls to `memory_resource::allocate` may throw.

### Return Value

A `std::pair` where `first` is an iterator to the existing or inserted element, and `second` is `true` if the insertion took place or `false` if the assignment took place.

### Parameters

Name | Description
--- | ---
`key` | The key used for lookup and insertion.
`m` | The value to insert or assign.

### Exceptions

Type | Thrown On
--- | ---
`boost::system::system_error` | The size of a key would exceed `string::max_size`.

Edit this page