From Jason Turner

[deque]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpz8a52aa_/{from.md → to.md} +67 -59
tmp/tmpz8a52aa_/{from.md → to.md} RENAMED
@@ -1,31 +1,30 @@
1
  ### Class template `deque` <a id="deque">[[deque]]</a>
2
 
3
- #### Class template `deque` overview <a id="deque.overview">[[deque.overview]]</a>
4
 
5
  A `deque` is a sequence container that supports random access iterators
6
- ([[random.access.iterators]]). In addition, it supports constant time
7
  insert and erase operations at the beginning or the end; insert and
8
  erase in the middle take linear time. That is, a deque is especially
9
  optimized for pushing and popping elements at the beginning and end.
10
  Storage management is handled automatically.
11
 
12
- A `deque` satisfies all of the requirements of a container, of a
13
- reversible container (given in tables in  [[container.requirements]]),
14
- of a sequence container, including the optional sequence container
15
- requirements ([[sequence.reqmts]]), and of an allocator-aware container
16
- (Table  [[tab:containers.allocatoraware]]). Descriptions are provided
17
- here only for operations on `deque` that are not described in one of
18
- these tables or for operations where there is additional semantic
19
- information.
20
 
21
  ``` cpp
22
  namespace std {
23
  template<class T, class Allocator = allocator<T>>
24
  class deque {
25
  public:
26
- // types:
27
  using value_type = T;
28
  using allocator_type = Allocator;
29
  using pointer = typename allocator_traits<Allocator>::pointer;
30
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
31
  using reference = value_type&;
@@ -59,11 +58,11 @@ namespace std {
59
  void assign(InputIterator first, InputIterator last);
60
  void assign(size_type n, const T& t);
61
  void assign(initializer_list<T>);
62
  allocator_type get_allocator() const noexcept;
63
 
64
- // iterators:
65
  iterator begin() noexcept;
66
  const_iterator begin() const noexcept;
67
  iterator end() noexcept;
68
  const_iterator end() const noexcept;
69
  reverse_iterator rbegin() noexcept;
@@ -75,18 +74,18 @@ namespace std {
75
  const_iterator cend() const noexcept;
76
  const_reverse_iterator crbegin() const noexcept;
77
  const_reverse_iterator crend() const noexcept;
78
 
79
  // [deque.capacity], capacity
80
- bool empty() const noexcept;
81
  size_type size() const noexcept;
82
  size_type max_size() const noexcept;
83
  void resize(size_type sz);
84
  void resize(size_type sz, const T& c);
85
  void shrink_to_fit();
86
 
87
- // element access:
88
  reference operator[](size_type n);
89
  const_reference operator[](size_type n) const;
90
  reference at(size_type n);
91
  const_reference at(size_type n) const;
92
  reference front();
@@ -119,36 +118,22 @@ namespace std {
119
  void swap(deque&)
120
  noexcept(allocator_traits<Allocator>::is_always_equal::value);
121
  void clear() noexcept;
122
  };
123
 
124
- template<class InputIterator,
125
- class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
126
  deque(InputIterator, InputIterator, Allocator = Allocator())
127
- -> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
128
 
129
- template <class T, class Allocator>
130
- bool operator==(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
131
- template <class T, class Allocator>
132
- bool operator< (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
133
- template <class T, class Allocator>
134
- bool operator!=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
135
- template <class T, class Allocator>
136
- bool operator> (const deque<T, Allocator>& x, const deque<T, Allocator>& y);
137
- template <class T, class Allocator>
138
- bool operator>=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
139
- template <class T, class Allocator>
140
- bool operator<=(const deque<T, Allocator>& x, const deque<T, Allocator>& y);
141
-
142
- // [deque.special], specialized algorithms
143
  template<class T, class Allocator>
144
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
145
  noexcept(noexcept(x.swap(y)));
146
  }
147
  ```
148
 
149
- #### `deque` constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
150
 
151
  ``` cpp
152
  explicit deque(const Allocator&);
153
  ```
154
 
@@ -161,22 +146,22 @@ explicit deque(size_type n, const Allocator& = Allocator());
161
  ```
162
 
163
  *Effects:* Constructs a `deque` with `n` default-inserted elements using
164
  the specified allocator.
165
 
166
- *Requires:* `T` shall be `DefaultInsertable` into `*this`.
167
 
168
  *Complexity:* Linear in `n`.
169
 
170
  ``` cpp
171
  deque(size_type n, const T& value, const Allocator& = Allocator());
172
  ```
173
 
174
  *Effects:* Constructs a `deque` with `n` copies of `value`, using the
175
  specified allocator.
176
 
177
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
178
 
179
  *Complexity:* Linear in `n`.
180
 
181
  ``` cpp
182
  template<class InputIterator>
@@ -186,55 +171,57 @@ template <class InputIterator>
186
  *Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
187
  using the specified allocator.
188
 
189
  *Complexity:* Linear in `distance(first, last)`.
190
 
191
- #### `deque` capacity <a id="deque.capacity">[[deque.capacity]]</a>
192
 
193
  ``` cpp
194
  void resize(size_type sz);
195
  ```
196
 
 
 
 
197
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
198
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
199
  to the sequence.
200
 
201
- *Requires:* `T` shall be `MoveInsertable` and `DefaultInsertable` into
202
- `*this`.
203
-
204
  ``` cpp
205
  void resize(size_type sz, const T& c);
206
  ```
207
 
 
 
208
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
209
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
210
  sequence.
211
 
212
- *Requires:* `T` shall be `CopyInsertable` into `*this`.
213
-
214
  ``` cpp
215
  void shrink_to_fit();
216
  ```
217
 
218
- *Requires:* `T` shall be `MoveInsertable` into `*this`.
219
 
220
  *Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
221
  but does not change the size of the sequence.
222
 
223
  [*Note 1*: The request is non-binding to allow latitude for
224
  implementation-specific optimizations. — *end note*]
225
 
226
- If an exception is thrown other than by the move constructor of a
227
- non-`CopyInsertable` `T` there are no effects.
 
228
 
229
- *Complexity:* Linear in the size of the sequence.
 
230
 
231
- *Remarks:* `shrink_to_fit` invalidates all the references, pointers, and
232
- iterators referring to the elements in the sequence as well as the
233
- past-the-end iterator.
234
 
235
- #### `deque` modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
236
 
237
  ``` cpp
238
  iterator insert(const_iterator position, const T& x);
239
  iterator insert(const_iterator position, T&& x);
240
  iterator insert(const_iterator position, size_type n, const T& x);
@@ -259,16 +246,16 @@ has no effect on the validity of references to elements of the deque.
259
 
260
  *Remarks:* If an exception is thrown other than by the copy constructor,
261
  move constructor, assignment operator, or move assignment operator of
262
  `T` there are no effects. If an exception is thrown while inserting a
263
  single element at either end, there are no effects. Otherwise, if an
264
- exception is thrown by the move constructor of a non-`CopyInsertable`
265
- `T`, the effects are unspecified.
266
 
267
  *Complexity:* The complexity is linear in the number of elements
268
  inserted plus the lesser of the distances to the beginning and end of
269
- the deque. Inserting a single element either at the beginning or end of
270
  a deque always takes constant time and causes a single call to a
271
  constructor of `T`.
272
 
273
  ``` cpp
274
  iterator erase(const_iterator position);
@@ -293,19 +280,40 @@ operations. — *end note*]
293
  as the number of elements erased, but the number of calls to the
294
  assignment operator of `T` is no more than the lesser of the number of
295
  elements before the erased elements and the number of elements after the
296
  erased elements.
297
 
298
- *Throws:* Nothing unless an exception is thrown by the copy constructor,
299
- move constructor, assignment operator, or move assignment operator of
300
- `T`.
301
 
302
- #### `deque` specialized algorithms <a id="deque.special">[[deque.special]]</a>
303
 
304
  ``` cpp
305
- template <class T, class Allocator>
306
- void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
307
- noexcept(noexcept(x.swap(y)));
308
  ```
309
 
310
- *Effects:* As if by `x.swap(y)`.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
311
 
 
1
  ### Class template `deque` <a id="deque">[[deque]]</a>
2
 
3
+ #### Overview <a id="deque.overview">[[deque.overview]]</a>
4
 
5
  A `deque` is a sequence container that supports random access iterators
6
+ [[random.access.iterators]]. In addition, it supports constant time
7
  insert and erase operations at the beginning or the end; insert and
8
  erase in the middle take linear time. That is, a deque is especially
9
  optimized for pushing and popping elements at the beginning and end.
10
  Storage management is handled automatically.
11
 
12
+ A `deque` meets all of the requirements of a container, of a reversible
13
+ container (given in tables in  [[container.requirements]]), of a
14
+ sequence container, including the optional sequence container
15
+ requirements [[sequence.reqmts]], and of an allocator-aware container (
16
+ [[container.alloc.req]]). Descriptions are provided here only for
17
+ operations on `deque` that are not described in one of these tables or
18
+ for operations where there is additional semantic information.
 
19
 
20
  ``` cpp
21
  namespace std {
22
  template<class T, class Allocator = allocator<T>>
23
  class deque {
24
  public:
25
+ // types
26
  using value_type = T;
27
  using allocator_type = Allocator;
28
  using pointer = typename allocator_traits<Allocator>::pointer;
29
  using const_pointer = typename allocator_traits<Allocator>::const_pointer;
30
  using reference = value_type&;
 
58
  void assign(InputIterator first, InputIterator last);
59
  void assign(size_type n, const T& t);
60
  void assign(initializer_list<T>);
61
  allocator_type get_allocator() const noexcept;
62
 
63
+ // iterators
64
  iterator begin() noexcept;
65
  const_iterator begin() const noexcept;
66
  iterator end() noexcept;
67
  const_iterator end() const noexcept;
68
  reverse_iterator rbegin() noexcept;
 
74
  const_iterator cend() const noexcept;
75
  const_reverse_iterator crbegin() const noexcept;
76
  const_reverse_iterator crend() const noexcept;
77
 
78
  // [deque.capacity], capacity
79
+ [[nodiscard]] bool empty() const noexcept;
80
  size_type size() const noexcept;
81
  size_type max_size() const noexcept;
82
  void resize(size_type sz);
83
  void resize(size_type sz, const T& c);
84
  void shrink_to_fit();
85
 
86
+ // element access
87
  reference operator[](size_type n);
88
  const_reference operator[](size_type n) const;
89
  reference at(size_type n);
90
  const_reference at(size_type n) const;
91
  reference front();
 
118
  void swap(deque&)
119
  noexcept(allocator_traits<Allocator>::is_always_equal::value);
120
  void clear() noexcept;
121
  };
122
 
123
+ template<class InputIterator, class Allocator = allocator<iter-value-type<InputIterator>>>
 
124
  deque(InputIterator, InputIterator, Allocator = Allocator())
125
+ -> deque<iter-value-type<InputIterator>, Allocator>;
126
 
127
+ // swap
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  template<class T, class Allocator>
129
  void swap(deque<T, Allocator>& x, deque<T, Allocator>& y)
130
  noexcept(noexcept(x.swap(y)));
131
  }
132
  ```
133
 
134
+ #### Constructors, copy, and assignment <a id="deque.cons">[[deque.cons]]</a>
135
 
136
  ``` cpp
137
  explicit deque(const Allocator&);
138
  ```
139
 
 
146
  ```
147
 
148
  *Effects:* Constructs a `deque` with `n` default-inserted elements using
149
  the specified allocator.
150
 
151
+ *Preconditions:* `T` is *Cpp17DefaultInsertable* into `*this`.
152
 
153
  *Complexity:* Linear in `n`.
154
 
155
  ``` cpp
156
  deque(size_type n, const T& value, const Allocator& = Allocator());
157
  ```
158
 
159
  *Effects:* Constructs a `deque` with `n` copies of `value`, using the
160
  specified allocator.
161
 
162
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
163
 
164
  *Complexity:* Linear in `n`.
165
 
166
  ``` cpp
167
  template<class InputIterator>
 
171
  *Effects:* Constructs a `deque` equal to the range \[`first`, `last`),
172
  using the specified allocator.
173
 
174
  *Complexity:* Linear in `distance(first, last)`.
175
 
176
+ #### Capacity <a id="deque.capacity">[[deque.capacity]]</a>
177
 
178
  ``` cpp
179
  void resize(size_type sz);
180
  ```
181
 
182
+ *Preconditions:* `T` is *Cpp17MoveInsertable* and
183
+ *Cpp17DefaultInsertable* into `*this`.
184
+
185
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
186
  the sequence. Otherwise, appends `sz - size()` default-inserted elements
187
  to the sequence.
188
 
 
 
 
189
  ``` cpp
190
  void resize(size_type sz, const T& c);
191
  ```
192
 
193
+ *Preconditions:* `T` is *Cpp17CopyInsertable* into `*this`.
194
+
195
  *Effects:* If `sz < size()`, erases the last `size() - sz` elements from
196
  the sequence. Otherwise, appends `sz - size()` copies of `c` to the
197
  sequence.
198
 
 
 
199
  ``` cpp
200
  void shrink_to_fit();
201
  ```
202
 
203
+ *Preconditions:* `T` is *Cpp17MoveInsertable* into `*this`.
204
 
205
  *Effects:* `shrink_to_fit` is a non-binding request to reduce memory use
206
  but does not change the size of the sequence.
207
 
208
  [*Note 1*: The request is non-binding to allow latitude for
209
  implementation-specific optimizations. — *end note*]
210
 
211
+ If the size is equal to the old capacity, or if an exception is thrown
212
+ other than by the move constructor of a non-*Cpp17CopyInsertable* `T`,
213
+ then there are no effects.
214
 
215
+ *Complexity:* If the size is not equal to the old capacity, linear in
216
+ the size of the sequence; otherwise constant.
217
 
218
+ *Remarks:* If the size is not equal to the old capacity, then
219
+ invalidates all the references, pointers, and iterators referring to the
220
+ elements in the sequence, as well as the past-the-end iterator.
221
 
222
+ #### Modifiers <a id="deque.modifiers">[[deque.modifiers]]</a>
223
 
224
  ``` cpp
225
  iterator insert(const_iterator position, const T& x);
226
  iterator insert(const_iterator position, T&& x);
227
  iterator insert(const_iterator position, size_type n, const T& x);
 
246
 
247
  *Remarks:* If an exception is thrown other than by the copy constructor,
248
  move constructor, assignment operator, or move assignment operator of
249
  `T` there are no effects. If an exception is thrown while inserting a
250
  single element at either end, there are no effects. Otherwise, if an
251
+ exception is thrown by the move constructor of a
252
+ non-*Cpp17CopyInsertable* `T`, the effects are unspecified.
253
 
254
  *Complexity:* The complexity is linear in the number of elements
255
  inserted plus the lesser of the distances to the beginning and end of
256
+ the deque. Inserting a single element at either the beginning or end of
257
  a deque always takes constant time and causes a single call to a
258
  constructor of `T`.
259
 
260
  ``` cpp
261
  iterator erase(const_iterator position);
 
280
  as the number of elements erased, but the number of calls to the
281
  assignment operator of `T` is no more than the lesser of the number of
282
  elements before the erased elements and the number of elements after the
283
  erased elements.
284
 
285
+ *Throws:* Nothing unless an exception is thrown by the assignment
286
+ operator of `T`.
 
287
 
288
+ #### Erasure <a id="deque.erasure">[[deque.erasure]]</a>
289
 
290
  ``` cpp
291
+ template<class T, class Allocator, class U>
292
+ typename deque<T, Allocator>::size_type
293
+ erase(deque<T, Allocator>& c, const U& value);
294
  ```
295
 
296
+ *Effects:* Equivalent to:
297
+
298
+ ``` cpp
299
+ auto it = remove(c.begin(), c.end(), value);
300
+ auto r = distance(it, c.end());
301
+ c.erase(it, c.end());
302
+ return r;
303
+ ```
304
+
305
+ ``` cpp
306
+ template<class T, class Allocator, class Predicate>
307
+ typename deque<T, Allocator>::size_type
308
+ erase_if(deque<T, Allocator>& c, Predicate pred);
309
+ ```
310
+
311
+ *Effects:* Equivalent to:
312
+
313
+ ``` cpp
314
+ auto it = remove_if(c.begin(), c.end(), pred);
315
+ auto r = distance(it, c.end());
316
+ c.erase(it, c.end());
317
+ return r;
318
+ ```
319