## `key_value_pair::key_value_pair`

Constructors.

### Synopsis

    template<
        class... Args>
    explicit
    key_value_pair(
        string_view key,
        Args&&... args); (1)

    explicit
    key_value_pair(
        std::pair< string_view, value > const& p,
        storage_ptr sp = {}); (2)

    explicit
    key_value_pair(
        std::pair< string_view, value >&& p,
        storage_ptr sp = {}); (3)

    key_value_pair(
        key_value_pair const& other,
        storage_ptr sp); (4)

    key_value_pair(
        key_value_pair const& other); (5)

    key_value_pair(
        key_value_pair&& other) noexcept; (6)

    key_value_pair(
        pilfered< key_value_pair > other) noexcept; (7)

### Description

Construct a key/value pair.

- (1) uses a copy of the characters of `key`, and constructs the value as if by `value(std::forward<Args>(args)...)`.

- (2) equivalent to `key_value_pair(p.first, p.second, sp)`.

- (3) equivalent to `key_value_pair(p.first, std::move(p.second), sp)`.

- (4) equivalent to `key_value_pair(other.key(), other.value(), sp)`.

- (5) equivalent to `key_value_pair(other.key(), other.value(), other.storage())`.

- (6) the pair s constructed by acquiring ownership of the contents of `other` using move semantics.

- (7) the pair is constructed by acquiring ownership of the contents of `other` using pilfer semantics. This is more efficient than move construction, when it is known that the moved-from object will be immediately destroyed afterwards.

With (2), (3), (4) the pair uses the memory resource of `sp`. With (5), (6), (7) it uses the memory resource of `other.storage()`. With (1) it uses whatever memory resource `value(std::forward<Args>(args)...)` would use. In any case the pair acquires shared ownership of its memory resource

After (6) `other` holds an empty key, and a null value with its current storage pointer.

After (7) `other` is not in a usable state and may only be destroyed.

### Complexity

Constant.

### Exception Safety

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

### Parameters

Name | Description
--- | ---
`key` | The key string to use.
`args` | Optional arguments forwarded to the `value` constructor.
`p` | A `std::pair` with the key string and `value` to construct with.
`sp` | A pointer to the `boost::container::pmr::memory_resource` to use.
`other` | Another key/value pair.

### Exceptions

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

### See Also

`pilfer`, Valueless Variants Considered Harmful.

Edit this page