array::array

## `array::array`

Constructors.

### Synopsis

    array() noexcept; (1)

    explicit
    array(
        storage_ptr sp) noexcept; (2)

    array(
        std::size_t count,
        value const& jv,
        storage_ptr sp = {}); (3)

    array(
        std::size_t count,
        storage_ptr sp = {}); (4)

    template<
        class InputIt>
    array(
        InputIt first,
        InputIt last,
        storage_ptr sp = {}); (5)

    array(
        std::initializer_list< value_ref > init,
        storage_ptr sp = {}); (6)

    array(
        array const& other); (7)

    array(
        array const& other,
        storage_ptr sp); (8)

    array(
        pilfered< array > other) noexcept; (9)

    array(
        array&& other) noexcept; (10)

    array(
        array&& other,
        storage_ptr sp); (11)

### Description

Constructs an array.

- (1), (2) the array is empty and has zero capacity.

- (3) the array is filled with `count` copies of `jv`.

- (4) the array is filled with `count` null values.

- (5) the array is filled with values in the range `[first, last)`, preserving order.

- (6) the array is filled with copies of the values in `init, preserving order.

- (7), (8) the array is filled with copies of the elements of `other`, preserving order.

- (9) the array acquires ownership of the contents of `other`.

- (10) equivalent to (9) if `*sp == *other.storage()`; otherwise equivalent to (8).

- (11) the array acquires 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), (4), (5), (6), (8), (10) the constructed array uses memory resource of `sp`. With (7), (9), and (11) it uses `other`'s memory resource. In either case the array will share the ownership of the memory resource. With (1) and (3) it uses the default memory resource.

After (9) `other` behaves as if newly constructed with its current storage pointer.

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

### Constraints

    std::is_constructible_v<value, std::iterator_traits<InputIt>::reference>

### Complexity

- (1), (2), (9), (11) constant.

- (3), (4) linear in `count`.

- (5) linear in `std::distance(first, last)`

- (6) linear in `init.size()`.

- (7), (8) linear in `other.size()`.

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

### Exception Safety

- (1), (2), (9), (11) no-throw guarantee.

- (3), (4), (6)–(8), (10) strong guarantee.

- (5) strong guarantee if `InputIt` satisfies LegacyForwardIterator, basic guarantee otherwise.

Calls to `memory_resource::allocate` may throw.

### Template Parameters

Type | Description
--- | ---
`InputIt` | a type satisfying the LegacyInputIterator requirement.

### Parameters

Name | Description
--- | ---
`sp` | A pointer to the `boost::container::pmr::memory_resource` to use. The container will acquire shared ownership of the memory resource.
`count` | The number of copies to insert.
`jv` | The value to be inserted.
`first` | An input iterator pointing to the first element to insert, or pointing to the end of the range.
`last` | An input iterator pointing to the end of the range.
`init` | The initializer list with elements to insert.
`other` | Another array.

### See Also

`pilfer`, Valueless Variants Considered Harmful.

Edit this page