string::operator=

## `string::operator=`

Assignment operators.

### Synopsis

    string&
    operator=(
        string const& other); (1)

    string&
    operator=(
        string&& other); (2)

    string&
    operator=(
        char const* s); (3)

    string&
    operator=(
        string_view other); (4)

### Description

- (1), (4) the contents are replaced with an element-wise copy of `other`.

- (2) takes ownership of `other`'s element storage if `*storage() == *other.storage()`; otherwise equivalent to (1).

- (3) the contents are replaced with an element-wise copy of null-terminated string `s`.

After (2), the moved-from array behaves as if newly constructed with its current storage pointer.

### Complexity

- (1), (4) linear in `other.size()`.

- (2) constant if `*storage() == *other.storage()`; otherwise linear in `other.size()`.

- (3) linear in `std::strlen(s)`.

### Exception Safety

(2) provides strong guarantee if `*storage() != *other.storage()` and no-throw guarantee otherwise. Other overloads provide strong guarantee. Calls to `memory_resource::allocate` may throw.

### Return Value

`*this`

### Parameters

Name | Description
--- | ---
`other` | The string to copy.
`s` | The null-terminated character string.

### Exceptions

Type | Thrown On
--- | ---
`boost::system::system_error` | `std::strlen(s) >` `max_size()`.
``boost::system::system_error`` | `other.size() >` `max_size()`.

Edit this page