From Jason Turner

[array]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpfp0r714u/{from.md → to.md} +91 -63
tmp/tmpfp0r714u/{from.md → to.md} RENAMED
@@ -1,32 +1,41 @@
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
18
- of a sequence container ([[sequence.reqmts]]). Descriptions are
19
- provided here only for operations on `array` that are not described in
20
- one of these tables and for operations where there is additional
21
- semantic information.
 
 
 
 
 
 
 
 
 
22
 
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&;
@@ -37,14 +46,14 @@ namespace std {
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
 
@@ -56,16 +65,16 @@ namespace std {
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();
@@ -80,83 +89,75 @@ namespace std {
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
90
- container requirements table in  [[container.requirements]]. In addition
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
 
161
  In the case that `N == 0`, `begin() == end() ==` unique value. The
162
  return value of `data()` is unspecified.
@@ -165,24 +166,51 @@ 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
  ```
180
 
181
- *Requires:* `I < N`. The program is ill-formed if `I` is out of bounds.
182
-
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>
@@ -191,10 +219,10 @@ 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
 
 
1
  ### Class template `array` <a id="array">[[array]]</a>
2
 
3
+ #### 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` meets all of the requirements of a container and of a
15
+ reversible container [[container.requirements]], except that a default
16
+ constructed `array` object is not empty and that `swap` does not have
17
+ constant complexity. An `array` meets some of the requirements of a
18
+ sequence container [[sequence.reqmts]]. Descriptions are provided here
19
+ only for operations on `array` that are not described in one of these
20
+ tables and for operations where there is additional semantic
21
+ information.
22
+
23
+ `array<T, N>` is a structural type [[temp.param]] if `T` is a structural
24
+ type. Two values `a1` and `a2` of type `array<T, N>` are
25
+ template-argument-equivalent [[temp.type]] if and only if each pair of
26
+ corresponding elements in `a1` and `a2` are
27
+ template-argument-equivalent.
28
+
29
+ The types `iterator` and `const_iterator` meet the constexpr iterator
30
+ requirements [[iterator.requirements.general]].
31
 
32
  ``` cpp
33
  namespace std {
34
  template<class T, size_t N>
35
  struct array {
36
+ // types
37
  using value_type = T;
38
  using pointer = T*;
39
  using const_pointer = const T*;
40
  using reference = T&;
41
  using const_reference = const T&;
 
46
  using reverse_iterator = std::reverse_iterator<iterator>;
47
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
48
 
49
  // no explicit construct/copy/destroy for aggregate type
50
 
51
+ constexpr void fill(const T& u);
52
+ constexpr void swap(array&) noexcept(is_nothrow_swappable_v<T>);
53
 
54
+ // iterators
55
  constexpr iterator begin() noexcept;
56
  constexpr const_iterator begin() const noexcept;
57
  constexpr iterator end() noexcept;
58
  constexpr const_iterator end() const noexcept;
59
 
 
65
  constexpr const_iterator cbegin() const noexcept;
66
  constexpr const_iterator cend() const noexcept;
67
  constexpr const_reverse_iterator crbegin() const noexcept;
68
  constexpr const_reverse_iterator crend() const noexcept;
69
 
70
+ // capacity
71
+ [[nodiscard]] constexpr bool empty() const noexcept;
72
  constexpr size_type size() const noexcept;
73
  constexpr size_type max_size() const noexcept;
74
 
75
+ // element access
76
  constexpr reference operator[](size_type n);
77
  constexpr const_reference operator[](size_type n) const;
78
  constexpr reference at(size_type n);
79
  constexpr const_reference at(size_type n) const;
80
  constexpr reference front();
 
89
  template<class T, class... U>
90
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
91
  }
92
  ```
93
 
94
+ #### Constructors, copy, and assignment <a id="array.cons">[[array.cons]]</a>
95
 
96
+ The conditions for an aggregate [[dcl.init.aggr]] shall be met. Class
97
  `array` relies on the implicitly-declared special member functions (
98
+ [[class.default.ctor]], [[class.dtor]], and [[class.copy.ctor]]) to
99
+ conform to the container requirements table in 
100
+ [[container.requirements]]. In addition to the requirements specified in
101
+ the container requirements table, the implicit move constructor and move
102
+ assignment operator for `array` require that `T` be
103
+ *Cpp17MoveConstructible* or *Cpp17MoveAssignable*, respectively.
104
 
105
  ``` cpp
106
  template<class T, class... U>
107
  array(T, U...) -> array<T, 1 + sizeof...(U)>;
108
  ```
109
 
110
+ *Mandates:* `(is_same_v<T, U> && ...)` is `true`.
 
111
 
112
+ #### Member functions <a id="array.members">[[array.members]]</a>
113
 
114
  ``` cpp
115
+ constexpr size_type size() const noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  ```
117
 
118
  *Returns:* `N`.
119
 
 
 
120
  ``` cpp
121
  constexpr T* data() noexcept;
122
  constexpr const T* data() const noexcept;
123
  ```
124
 
125
+ *Returns:* A pointer such that \[`data()`, `data() + size()`) is a valid
126
+ range. For a non-empty array, `data()` `==` `addressof(front())`.
 
 
127
 
128
  ``` cpp
129
+ constexpr void fill(const T& u);
130
  ```
131
 
132
  *Effects:* As if by `fill_n(begin(), N, u)`.
133
 
 
 
134
  ``` cpp
135
+ constexpr void swap(array& y) noexcept(is_nothrow_swappable_v<T>);
136
  ```
137
 
138
  *Effects:* Equivalent to `swap_ranges(begin(), end(), y.begin())`.
139
 
140
  [*Note 1*: Unlike the `swap` function for other containers,
141
  `array::swap` takes linear time, may exit via an exception, and does not
142
  cause iterators to become associated with the other
143
  container. — *end note*]
144
 
145
+ #### Specialized algorithms <a id="array.special">[[array.special]]</a>
146
+
147
+ ``` cpp
148
+ template<class T, size_t N>
149
+ constexpr void swap(array<T, N>& x, array<T, N>& y) noexcept(noexcept(x.swap(y)));
150
+ ```
151
+
152
+ *Constraints:* `N == 0` or `is_swappable_v<T>` is `true`.
153
+
154
+ *Effects:* As if by `x.swap(y)`.
155
+
156
+ *Complexity:* Linear in `N`.
157
+
158
+ #### Zero-sized arrays <a id="array.zero">[[array.zero]]</a>
159
 
160
  `array` shall provide support for the special case `N == 0`.
161
 
162
  In the case that `N == 0`, `begin() == end() ==` unique value. The
163
  return value of `data()` is unspecified.
 
166
  undefined.
167
 
168
  Member function `swap()` shall have a non-throwing exception
169
  specification.
170
 
171
+ #### Array creation functions <a id="array.creation">[[array.creation]]</a>
172
+
173
+ ``` cpp
174
+ template<class T, size_t N>
175
+ constexpr array<remove_cv_t<T>, N> to_array(T (&a)[N]);
176
+ ```
177
+
178
+ *Mandates:* `is_array_v<T>` is `false` and `is_constructible_v<T, T&>`
179
+ is `true`.
180
+
181
+ *Preconditions:* `T` meets the *Cpp17CopyConstructible* requirements.
182
+
183
+ *Returns:* `{{ a[0], `…`, a[N - 1] }}`.
184
+
185
+ ``` cpp
186
+ template<class T, size_t N>
187
+ constexpr array<remove_cv_t<T>, N> to_array(T (&&a)[N]);
188
+ ```
189
+
190
+ *Mandates:* `is_array_v<T>` is `false` and `is_move_constructible_v<T>`
191
+ is `true`.
192
+
193
+ *Preconditions:* `T` meets the *Cpp17MoveConstructible* requirements.
194
+
195
+ *Returns:* `{{ std::move(a[0]), `…`, std::move(a[N - 1]) }}`.
196
+
197
+ #### Tuple interface <a id="array.tuple">[[array.tuple]]</a>
198
 
199
  ``` cpp
200
  template<class T, size_t N>
201
  struct tuple_size<array<T, N>> : integral_constant<size_t, N> { };
202
  ```
203
 
204
  ``` cpp
205
+ template<size_t I, class T, size_t N>
206
+ struct tuple_element<I, array<T, N>> {
207
+ using type = T;
208
+ };
209
  ```
210
 
211
+ *Mandates:* `I < N` is `true`.
 
 
212
 
213
  ``` cpp
214
  template<size_t I, class T, size_t N>
215
  constexpr T& get(array<T, N>& a) noexcept;
216
  template<size_t I, class T, size_t N>
 
219
  constexpr const T& get(const array<T, N>& a) noexcept;
220
  template<size_t I, class T, size_t N>
221
  constexpr const T&& get(const array<T, N>&& a) noexcept;
222
  ```
223
 
224
+ *Mandates:* `I < N` is `true`.
225
 
226
+ *Returns:* A reference to the `I`ᵗʰ element of `a`, where indexing is
227
  zero-based.
228