swap

## `swap`

Swap two objects.

### Synopsis

Defined in header <boost/json/object.hpp>.

    void
    swap(
        object& lhs,
        object& rhs);

### Description

Exchanges the contents of the object `lhs` with another object `rhs`. Ownership of the respective `boost::container::pmr::memory_resource` objects is not transferred. If `&lhs == &rhs`, this function call has no effect.

- If `*lhs.storage() == *rhs.storage()` all iterators and references remain valid.

- Otherwise, the contents are logically swapped by making copies, which can throw. In this case all iterators and references are invalidated.

### Complexity

If `*lhs.storage() == *rhs.storage()`, then constant; otherwise linear in `lhs.size() + rhs.size()`.

### Exception Safety

No-throw guarantee if `*lhs.storage() == *rhs.storage()`. Otherwise strong guarantee. Calls to `memory_resource::allocate` may throw.

### Parameters

Name | Description
--- | ---
`lhs` | The object to exchange.
`rhs` | The object to exchange.

### See Also

`object::swap`

Convenience header <boost/json.hpp>

Edit this page