Files
2025-10-25 03:02:53 +03:00

136 lines
4.6 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[vector.cons]
# 23 Containers library [[containers]](./#containers)
## 23.3 Sequence containers [[sequences]](sequences#vector.cons)
### 23.3.13 Class template vector [[vector]](vector#cons)
#### 23.3.13.2 Constructors [vector.cons]
[🔗](#lib:vector,constructor)
`constexpr explicit vector(const Allocator&) noexcept;
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9992)
*Effects*: Constructs an empty vector, using the
specified allocator[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L9997)
*Complexity*: Constant[.](#2.sentence-1)
[🔗](#lib:vector,constructor_)
`constexpr explicit vector(size_type n, const Allocator& = Allocator());
`
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10008)
*Preconditions*: T is *Cpp17DefaultInsertable* into vector[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10012)
*Effects*: Constructs a vector with n default-inserted elements using the specified allocator[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10017)
*Complexity*: Linear in n[.](#5.sentence-1)
[🔗](#lib:vector,constructor__)
`constexpr vector(size_type n, const T& value,
const Allocator& = Allocator());
`
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10029)
*Preconditions*: T is*Cpp17CopyInsertable* into vector[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10034)
*Effects*: Constructs a vector with n copies of value, using the specified allocator[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10039)
*Complexity*: Linear in n[.](#8.sentence-1)
[🔗](#lib:vector,constructor___)
`template<class InputIterator>
constexpr vector(InputIterator first, InputIterator last,
const Allocator& = Allocator());
`
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10052)
*Effects*: Constructs a vector equal to the
range [first, last), using the specified allocator[.](#9.sentence-1)
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10057)
*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[.](#10.sentence-1)
It makes orderN calls to the copy constructor ofT and orderlogN reallocations if they are just input iterators[.](#10.sentence-2)
[🔗](#lib:vector,constructor____)
`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](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10085)
*Effects*: Constructs a vector object with the elements of the range rg,
using the specified allocator[.](#11.sentence-1)
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10090)
*Complexity*: Initializes exactly N elements
from the results of dereferencing successive iterators of rg,
where N is ranges::distance(rg)[.](#12.sentence-1)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L10096)
Performs no reallocations if:
- [(13.1)](#13.1)
R models ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]"), andranges::distance(rg) <= ranges::reserve_hint(rg) is true, or
- [(13.2)](#13.2)
R models ranges::[forward_range](range.refinements#concept:forward_range "25.4.6Other range refinements[range.refinements]") andR does not model ranges::[approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3Approximately sized ranges[range.approximately.sized]")[.](#13.sentence-1)
Otherwise, performs order logN reallocations and
order N calls to the copy or move constructor of T[.](#13.sentence-2)