tmp/tmp61jbpcix/{from.md → to.md}
RENAMED
|
@@ -1,25 +1,17 @@
|
|
| 1 |
### Class template `array` <a id="array">[[array]]</a>
|
| 2 |
|
| 3 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 4 |
|
| 5 |
The header `<array>` defines a class template for storing fixed-size
|
| 6 |
-
sequences of objects. An `array`
|
| 7 |
-
instance of `array<T, N>` stores
|
| 8 |
-
`size() == N` is an invariant.
|
| 9 |
-
contiguously, meaning that if `a` is an `array<T, N>` then it obeys the
|
| 10 |
-
identity `&a[n] == &a[0] + n` for all `0 <= n < N`.
|
| 11 |
|
| 12 |
-
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 13 |
-
with
|
| 14 |
-
|
| 15 |
-
``` cpp
|
| 16 |
-
array<T, N> a = { initializer-list };
|
| 17 |
-
```
|
| 18 |
-
|
| 19 |
-
where *initializer-list* is a comma-separated list of up to `N` elements
|
| 20 |
-
whose types are convertible to `T`.
|
| 21 |
|
| 22 |
An `array` satisfies all of the requirements of a container and of a
|
| 23 |
reversible container ([[container.requirements]]), except that a
|
| 24 |
default constructed `array` object is not empty and that `swap` does not
|
| 25 |
have constant complexity. An `array` satisfies some of the requirements
|
|
@@ -31,70 +23,67 @@ semantic information.
|
|
| 31 |
``` cpp
|
| 32 |
namespace std {
|
| 33 |
template <class T, size_t N>
|
| 34 |
struct array {
|
| 35 |
// types:
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
T elems[N]; // exposition only
|
| 49 |
|
| 50 |
// no explicit construct/copy/destroy for aggregate type
|
| 51 |
|
| 52 |
void fill(const T& u);
|
| 53 |
-
void swap(array&) noexcept(
|
| 54 |
|
| 55 |
// iterators:
|
| 56 |
-
iterator begin() noexcept;
|
| 57 |
-
const_iterator begin() const noexcept;
|
| 58 |
-
iterator end() noexcept;
|
| 59 |
-
const_iterator end() const noexcept;
|
| 60 |
|
| 61 |
-
reverse_iterator rbegin() noexcept;
|
| 62 |
-
const_reverse_iterator rbegin() const noexcept;
|
| 63 |
-
reverse_iterator rend() noexcept;
|
| 64 |
-
const_reverse_iterator rend() const noexcept;
|
| 65 |
|
| 66 |
-
const_iterator cbegin() const noexcept;
|
| 67 |
-
const_iterator cend() const noexcept;
|
| 68 |
-
const_reverse_iterator crbegin() const noexcept;
|
| 69 |
-
const_reverse_iterator crend() const noexcept;
|
| 70 |
|
| 71 |
// capacity:
|
|
|
|
| 72 |
constexpr size_type size() const noexcept;
|
| 73 |
constexpr size_type max_size() const noexcept;
|
| 74 |
-
constexpr bool empty() const noexcept;
|
| 75 |
|
| 76 |
// element access:
|
| 77 |
-
reference
|
| 78 |
constexpr const_reference operator[](size_type n) const;
|
| 79 |
-
reference
|
| 80 |
constexpr const_reference at(size_type n) const;
|
| 81 |
-
reference
|
| 82 |
constexpr const_reference front() const;
|
| 83 |
-
reference
|
| 84 |
constexpr const_reference back() const;
|
| 85 |
|
| 86 |
-
T * data() noexcept;
|
| 87 |
-
const T * data() const noexcept;
|
| 88 |
};
|
|
|
|
|
|
|
|
|
|
| 89 |
}
|
| 90 |
```
|
| 91 |
|
| 92 |
-
The member variable `elems` is shown for exposition only, to emphasize
|
| 93 |
-
that `array` is a class aggregate. The name `elems` is not part of
|
| 94 |
-
`array`’s interface.
|
| 95 |
-
|
| 96 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 97 |
|
| 98 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 99 |
`array` relies on the implicitly-declared special member functions (
|
| 100 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
@@ -102,63 +91,70 @@ container requirements table in [[container.requirements]]. In addition
|
|
| 102 |
to the requirements specified in the container requirements table, the
|
| 103 |
implicit move constructor and move assignment operator for `array`
|
| 104 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 105 |
respectively.
|
| 106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
-
template <class T, size_t N>
|
|
|
|
| 111 |
```
|
| 112 |
|
| 113 |
-
*
|
|
|
|
| 114 |
|
| 115 |
-
``
|
| 116 |
-
x.swap(y);
|
| 117 |
-
```
|
| 118 |
|
| 119 |
*Complexity:* Linear in `N`.
|
| 120 |
|
| 121 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 125 |
```
|
| 126 |
|
| 127 |
-
*Returns:* `N`
|
| 128 |
|
| 129 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 130 |
|
| 131 |
``` cpp
|
| 132 |
-
T* data() noexcept;
|
| 133 |
-
const T* data() const noexcept;
|
| 134 |
```
|
| 135 |
|
| 136 |
-
*Returns:* `
|
|
|
|
| 137 |
|
| 138 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
void fill(const T& u);
|
| 142 |
```
|
| 143 |
|
| 144 |
-
*Effects:* `fill_n(begin(), N, u)`
|
| 145 |
|
| 146 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 147 |
|
| 148 |
``` cpp
|
| 149 |
-
void swap(array& y) noexcept(
|
| 150 |
```
|
| 151 |
|
| 152 |
-
*Effects:* `swap_ranges(begin(), end(), y.begin())`
|
| 153 |
|
| 154 |
-
*
|
| 155 |
-
exception
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
takes linear time, may exit via an exception, and does not cause
|
| 159 |
-
iterators to become associated with the other container.
|
| 160 |
|
| 161 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 162 |
|
| 163 |
`array` shall provide support for the special case `N == 0`.
|
| 164 |
|
|
@@ -166,19 +162,18 @@ In the case that `N == 0`, `begin() == end() ==` unique value. The
|
|
| 166 |
return value of `data()` is unspecified.
|
| 167 |
|
| 168 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 169 |
undefined.
|
| 170 |
|
| 171 |
-
Member function `swap()` shall have a
|
| 172 |
-
|
| 173 |
|
| 174 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 175 |
|
| 176 |
``` cpp
|
| 177 |
template <class T, size_t N>
|
| 178 |
-
struct tuple_size<array<T, N>>
|
| 179 |
-
: integral_constant<size_t, N> { };
|
| 180 |
```
|
| 181 |
|
| 182 |
``` cpp
|
| 183 |
tuple_element<I, array<T, N>>::type
|
| 184 |
```
|
|
@@ -188,29 +183,18 @@ tuple_element<I, array<T, N> >::type
|
|
| 188 |
*Value:* The type T.
|
| 189 |
|
| 190 |
``` cpp
|
| 191 |
template <size_t I, class T, size_t N>
|
| 192 |
constexpr T& get(array<T, N>& a) noexcept;
|
| 193 |
-
```
|
| 194 |
-
|
| 195 |
-
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 196 |
-
|
| 197 |
-
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 198 |
-
zero-based.
|
| 199 |
-
|
| 200 |
-
``` cpp
|
| 201 |
template <size_t I, class T, size_t N>
|
| 202 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
| 203 |
-
```
|
| 204 |
-
|
| 205 |
-
*Effects:* Equivalent to `return std::move(get<I>(a));`
|
| 206 |
-
|
| 207 |
-
``` cpp
|
| 208 |
template <size_t I, class T, size_t N>
|
| 209 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
|
|
|
|
|
|
| 210 |
```
|
| 211 |
|
| 212 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 213 |
|
| 214 |
-
*Returns:* A
|
| 215 |
-
|
| 216 |
|
|
|
|
| 1 |
### Class template `array` <a id="array">[[array]]</a>
|
| 2 |
|
| 3 |
#### Class template `array` overview <a id="array.overview">[[array.overview]]</a>
|
| 4 |
|
| 5 |
The header `<array>` defines a class template for storing fixed-size
|
| 6 |
+
sequences of objects. An `array` is a contiguous container (
|
| 7 |
+
[[container.requirements.general]]). An instance of `array<T, N>` stores
|
| 8 |
+
`N` elements of type `T`, so that `size() == N` is an invariant.
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
An `array` is an aggregate ([[dcl.init.aggr]]) that can be
|
| 11 |
+
list-initialized with up to `N` elements whose types are convertible to
|
| 12 |
+
`T`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
An `array` satisfies all of the requirements of a container and of a
|
| 15 |
reversible container ([[container.requirements]]), except that a
|
| 16 |
default constructed `array` object is not empty and that `swap` does not
|
| 17 |
have constant complexity. An `array` satisfies some of the requirements
|
|
|
|
| 23 |
``` cpp
|
| 24 |
namespace std {
|
| 25 |
template <class T, size_t N>
|
| 26 |
struct array {
|
| 27 |
// types:
|
| 28 |
+
using value_type = T;
|
| 29 |
+
using pointer = T*;
|
| 30 |
+
using const_pointer = const T*;
|
| 31 |
+
using reference = T&;
|
| 32 |
+
using const_reference = const T&;
|
| 33 |
+
using size_type = size_t;
|
| 34 |
+
using difference_type = ptrdiff_t;
|
| 35 |
+
using iterator = implementation-defined // type of array::iterator; // see [container.requirements]
|
| 36 |
+
using const_iterator = implementation-defined // type of array::const_iterator; // see [container.requirements]
|
| 37 |
+
using reverse_iterator = std::reverse_iterator<iterator>;
|
| 38 |
+
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
|
|
|
|
|
|
| 39 |
|
| 40 |
// no explicit construct/copy/destroy for aggregate type
|
| 41 |
|
| 42 |
void fill(const T& u);
|
| 43 |
+
void swap(array&) noexcept(is_nothrow_swappable_v<T>);
|
| 44 |
|
| 45 |
// iterators:
|
| 46 |
+
constexpr iterator begin() noexcept;
|
| 47 |
+
constexpr const_iterator begin() const noexcept;
|
| 48 |
+
constexpr iterator end() noexcept;
|
| 49 |
+
constexpr const_iterator end() const noexcept;
|
| 50 |
|
| 51 |
+
constexpr reverse_iterator rbegin() noexcept;
|
| 52 |
+
constexpr const_reverse_iterator rbegin() const noexcept;
|
| 53 |
+
constexpr reverse_iterator rend() noexcept;
|
| 54 |
+
constexpr const_reverse_iterator rend() const noexcept;
|
| 55 |
|
| 56 |
+
constexpr const_iterator cbegin() const noexcept;
|
| 57 |
+
constexpr const_iterator cend() const noexcept;
|
| 58 |
+
constexpr const_reverse_iterator crbegin() const noexcept;
|
| 59 |
+
constexpr const_reverse_iterator crend() const noexcept;
|
| 60 |
|
| 61 |
// capacity:
|
| 62 |
+
constexpr bool empty() const noexcept;
|
| 63 |
constexpr size_type size() const noexcept;
|
| 64 |
constexpr size_type max_size() const noexcept;
|
|
|
|
| 65 |
|
| 66 |
// element access:
|
| 67 |
+
constexpr reference operator[](size_type n);
|
| 68 |
constexpr const_reference operator[](size_type n) const;
|
| 69 |
+
constexpr reference at(size_type n);
|
| 70 |
constexpr const_reference at(size_type n) const;
|
| 71 |
+
constexpr reference front();
|
| 72 |
constexpr const_reference front() const;
|
| 73 |
+
constexpr reference back();
|
| 74 |
constexpr const_reference back() const;
|
| 75 |
|
| 76 |
+
constexpr T * data() noexcept;
|
| 77 |
+
constexpr const T * data() const noexcept;
|
| 78 |
};
|
| 79 |
+
|
| 80 |
+
template<class T, class... U>
|
| 81 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 82 |
}
|
| 83 |
```
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
#### `array` constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
|
| 86 |
|
| 87 |
The conditions for an aggregate ([[dcl.init.aggr]]) shall be met. Class
|
| 88 |
`array` relies on the implicitly-declared special member functions (
|
| 89 |
[[class.ctor]], [[class.dtor]], and [[class.copy]]) to conform to the
|
|
|
|
| 91 |
to the requirements specified in the container requirements table, the
|
| 92 |
implicit move constructor and move assignment operator for `array`
|
| 93 |
require that `T` be `MoveConstructible` or `MoveAssignable`,
|
| 94 |
respectively.
|
| 95 |
|
| 96 |
+
``` cpp
|
| 97 |
+
template<class T, class... U>
|
| 98 |
+
array(T, U...) -> array<T, 1 + sizeof...(U)>;
|
| 99 |
+
```
|
| 100 |
+
|
| 101 |
+
*Requires:* `(is_same_v<T, U> && ...)` is `true`. Otherwise the program
|
| 102 |
+
is ill-formed.
|
| 103 |
+
|
| 104 |
#### `array` specialized algorithms <a id="array.special">[[array.special]]</a>
|
| 105 |
|
| 106 |
``` cpp
|
| 107 |
+
template <class T, size_t N>
|
| 108 |
+
void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
|
| 109 |
```
|
| 110 |
|
| 111 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 112 |
+
unless `N == 0` or `is_swappable_v<T>` is `true`.
|
| 113 |
|
| 114 |
+
*Effects:* As if by `x.swap(y)`.
|
|
|
|
|
|
|
| 115 |
|
| 116 |
*Complexity:* Linear in `N`.
|
| 117 |
|
| 118 |
#### `array::size` <a id="array.size">[[array.size]]</a>
|
| 119 |
|
| 120 |
``` cpp
|
| 121 |
template <class T, size_t N> constexpr size_type array<T, N>::size() const noexcept;
|
| 122 |
```
|
| 123 |
|
| 124 |
+
*Returns:* `N`.
|
| 125 |
|
| 126 |
#### `array::data` <a id="array.data">[[array.data]]</a>
|
| 127 |
|
| 128 |
``` cpp
|
| 129 |
+
constexpr T* data() noexcept;
|
| 130 |
+
constexpr const T* data() const noexcept;
|
| 131 |
```
|
| 132 |
|
| 133 |
+
*Returns:* A pointer such that `data() == addressof(front())`, and
|
| 134 |
+
\[`data()`, `data() + size()`) is a valid range.
|
| 135 |
|
| 136 |
#### `array::fill` <a id="array.fill">[[array.fill]]</a>
|
| 137 |
|
| 138 |
``` cpp
|
| 139 |
void fill(const T& u);
|
| 140 |
```
|
| 141 |
|
| 142 |
+
*Effects:* As if by `fill_n(begin(), N, u)`.
|
| 143 |
|
| 144 |
#### `array::swap` <a id="array.swap">[[array.swap]]</a>
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
+
void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
|
| 148 |
```
|
| 149 |
|
| 150 |
+
*Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
|
| 151 |
|
| 152 |
+
[*Note 1*: Unlike the `swap` function for other containers,
|
| 153 |
+
`array::swap` takes linear time, may exit via an exception, and does not
|
| 154 |
+
cause iterators to become associated with the other
|
| 155 |
+
container. — *end note*]
|
|
|
|
|
|
|
| 156 |
|
| 157 |
#### Zero sized arrays <a id="array.zero">[[array.zero]]</a>
|
| 158 |
|
| 159 |
`array` shall provide support for the special case `N == 0`.
|
| 160 |
|
|
|
|
| 162 |
return value of `data()` is unspecified.
|
| 163 |
|
| 164 |
The effect of calling `front()` or `back()` for a zero-sized array is
|
| 165 |
undefined.
|
| 166 |
|
| 167 |
+
Member function `swap()` shall have a non-throwing exception
|
| 168 |
+
specification.
|
| 169 |
|
| 170 |
#### Tuple interface to class template `array` <a id="array.tuple">[[array.tuple]]</a>
|
| 171 |
|
| 172 |
``` cpp
|
| 173 |
template <class T, size_t N>
|
| 174 |
+
struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
|
|
|
|
| 175 |
```
|
| 176 |
|
| 177 |
``` cpp
|
| 178 |
tuple_element<I, array<T, N>>::type
|
| 179 |
```
|
|
|
|
| 183 |
*Value:* The type T.
|
| 184 |
|
| 185 |
``` cpp
|
| 186 |
template <size_t I, class T, size_t N>
|
| 187 |
constexpr T& get(array<T, N>& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
template <size_t I, class T, size_t N>
|
| 189 |
constexpr T&& get(array<T, N>&& a) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
template <size_t I, class T, size_t N>
|
| 191 |
constexpr const T& get(const array<T, N>& a) noexcept;
|
| 192 |
+
template <size_t I, class T, size_t N>
|
| 193 |
+
constexpr const T&& get(const array<T, N>&& a) noexcept;
|
| 194 |
```
|
| 195 |
|
| 196 |
*Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
|
| 197 |
|
| 198 |
+
*Returns:* A reference to the `I`th element of `a`, where indexing is
|
| 199 |
+
zero-based.
|
| 200 |
|