Files
cppdraft_translate/cppdraft/vector/cons.md
2025-10-25 03:02:53 +03:00

4.6 KiB
Raw Blame History

[vector.cons]

23 Containers library [containers]

23.3 Sequence containers [sequences]

23.3.13 Class template vector [vector]

23.3.13.2 Constructors [vector.cons]

🔗

constexpr explicit vector(const Allocator&) noexcept;

1

#

Effects: Constructs an empty vector, using the specified allocator.

2

#

Complexity: Constant.

🔗

constexpr explicit vector(size_type n, const Allocator& = Allocator());

3

#

Preconditions: T is Cpp17DefaultInsertable into vector.

4

#

Effects: Constructs a vector with n default-inserted elements using the specified allocator.

5

#

Complexity: Linear in n.

🔗

constexpr vector(size_type n, const T& value, const Allocator& = Allocator());

6

#

Preconditions: T isCpp17CopyInsertable into vector.

7

#

Effects: Constructs a vector with n copies of value, using the specified allocator.

8

#

Complexity: Linear in n.

🔗

template<class InputIterator> constexpr vector(InputIterator first, InputIterator last, const Allocator& = Allocator());

9

#

Effects: Constructs a vector equal to the range [first, last), using the specified allocator.

10

#

Complexity: Makes only N calls to the copy constructor ofT (where N is the distance betweenfirst andlast) and no reallocations ifInputIterator meets the Cpp17ForwardIterator requirements.

It makes orderN calls to the copy constructor ofT and orderlogN reallocations if they are just input iterators.

🔗

template<[container-compatible-range](container.intro.reqmts#concept:container-compatible-range "23.2.2.1Introduction[container.intro.reqmts]")<T> R> constexpr vector(from_range_t, R&& rg, const Allocator& = Allocator());

11

#

Effects: Constructs a vector object with the elements of the range rg, using the specified allocator.

12

#

Complexity: Initializes exactly N elements from the results of dereferencing successive iterators of rg, where N is ranges::distance(rg).

13

#

Performs no reallocations if:

R models ranges::approximately_sized_range, andranges::distance(rg) <= ranges::reserve_hint(rg) is true, or

R models ranges::forward_range andR does not model ranges::approximately_sized_range.

Otherwise, performs order logN reallocations and order N calls to the copy or move constructor of T.