- tmp/tmp45u5vclh/{from.md → to.md} +170 -127
tmp/tmp45u5vclh/{from.md → to.md}
RENAMED
|
@@ -8,23 +8,38 @@ The headers `<queue>` and `<stack>` define the container adaptors
|
|
| 8 |
The container adaptors each take a `Container` template parameter, and
|
| 9 |
each constructor takes a `Container` reference argument. This container
|
| 10 |
is copied into the `Container` member of each adaptor. If the container
|
| 11 |
takes an allocator, then a compatible allocator may be passed in to the
|
| 12 |
adaptor’s constructor. Otherwise, normal copy or move construction is
|
| 13 |
-
used for the container argument.
|
|
|
|
|
|
|
| 14 |
|
| 15 |
For container adaptors, no `swap` function throws an exception unless
|
| 16 |
that exception is thrown by the swap of the adaptor’s `Container` or
|
| 17 |
`Compare` object (if any).
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
### Header `<queue>` synopsis <a id="queue.syn">[[queue.syn]]</a>
|
| 20 |
|
| 21 |
``` cpp
|
| 22 |
#include <initializer_list>
|
| 23 |
|
| 24 |
namespace std {
|
| 25 |
-
|
| 26 |
template <class T, class Container = deque<T>> class queue;
|
| 27 |
template <class T, class Container = vector<T>,
|
| 28 |
class Compare = less<typename Container::value_type>>
|
| 29 |
class priority_queue;
|
| 30 |
|
|
@@ -47,10 +62,34 @@ namespace std {
|
|
| 47 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 48 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 49 |
}
|
| 50 |
```
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
### Class template `queue` <a id="queue">[[queue]]</a>
|
| 53 |
|
| 54 |
#### `queue` definition <a id="queue.defn">[[queue.defn]]</a>
|
| 55 |
|
| 56 |
Any sequence container supporting operations `front()`, `back()`,
|
|
@@ -60,15 +99,16 @@ particular, `list` ([[list]]) and `deque` ([[deque]]) can be used.
|
|
| 60 |
``` cpp
|
| 61 |
namespace std {
|
| 62 |
template <class T, class Container = deque<T>>
|
| 63 |
class queue {
|
| 64 |
public:
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
protected:
|
| 71 |
Container c;
|
| 72 |
|
| 73 |
public:
|
| 74 |
explicit queue(const Container&);
|
|
@@ -85,17 +125,23 @@ namespace std {
|
|
| 85 |
const_reference front() const { return c.front(); }
|
| 86 |
reference back() { return c.back(); }
|
| 87 |
const_reference back() const { return c.back(); }
|
| 88 |
void push(const value_type& x) { c.push_back(x); }
|
| 89 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 90 |
-
template <class... Args>
|
| 91 |
-
{ c.emplace_back(std::forward<Args>(args)...); }
|
| 92 |
void pop() { c.pop_front(); }
|
| 93 |
-
void swap(queue& q) noexcept(
|
| 94 |
{ using std::swap; swap(c, q.c); }
|
| 95 |
};
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
template <class T, class Container>
|
| 98 |
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
| 99 |
template <class T, class Container>
|
| 100 |
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
| 101 |
template <class T, class Container>
|
|
@@ -130,91 +176,80 @@ explicit queue(Container&& cont = Container());
|
|
| 130 |
|
| 131 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 132 |
|
| 133 |
#### `queue` constructors with allocators <a id="queue.cons.alloc">[[queue.cons.alloc]]</a>
|
| 134 |
|
| 135 |
-
If `
|
| 136 |
-
|
| 137 |
-
resolution.
|
| 138 |
|
| 139 |
``` cpp
|
| 140 |
-
template <class Alloc>
|
| 141 |
-
explicit queue(const Alloc& a);
|
| 142 |
```
|
| 143 |
|
| 144 |
*Effects:* Initializes `c` with `a`.
|
| 145 |
|
| 146 |
``` cpp
|
| 147 |
-
template <class Alloc>
|
| 148 |
-
queue(const container_type& cont, const Alloc& a);
|
| 149 |
```
|
| 150 |
|
| 151 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 152 |
the second argument.
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
-
template <class Alloc>
|
| 156 |
-
queue(container_type&& cont, const Alloc& a);
|
| 157 |
```
|
| 158 |
|
| 159 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 160 |
and `a` as the second argument.
|
| 161 |
|
| 162 |
``` cpp
|
| 163 |
-
template <class Alloc>
|
| 164 |
-
queue(const queue& q, const Alloc& a);
|
| 165 |
```
|
| 166 |
|
| 167 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 168 |
the second argument.
|
| 169 |
|
| 170 |
``` cpp
|
| 171 |
-
template <class Alloc>
|
| 172 |
-
queue(queue&& q, const Alloc& a);
|
| 173 |
```
|
| 174 |
|
| 175 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 176 |
and `a` as the second argument.
|
| 177 |
|
| 178 |
#### `queue` operators <a id="queue.ops">[[queue.ops]]</a>
|
| 179 |
|
| 180 |
``` cpp
|
| 181 |
template <class T, class Container>
|
| 182 |
-
|
| 183 |
-
const queue<T, Container>& y);
|
| 184 |
```
|
| 185 |
|
| 186 |
*Returns:* `x.c == y.c`.
|
| 187 |
|
| 188 |
``` cpp
|
| 189 |
template <class T, class Container>
|
| 190 |
-
|
| 191 |
-
const queue<T, Container>& y);
|
| 192 |
```
|
| 193 |
|
| 194 |
*Returns:* `x.c != y.c`.
|
| 195 |
|
| 196 |
``` cpp
|
| 197 |
template <class T, class Container>
|
| 198 |
-
|
| 199 |
-
const queue<T, Container>& y);
|
| 200 |
```
|
| 201 |
|
| 202 |
*Returns:* `x.c < y.c`.
|
| 203 |
|
| 204 |
``` cpp
|
| 205 |
template <class T, class Container>
|
| 206 |
-
|
| 207 |
-
const queue<T, Container>& y);
|
| 208 |
```
|
| 209 |
|
| 210 |
*Returns:* `x.c <= y.c`.
|
| 211 |
|
| 212 |
``` cpp
|
| 213 |
template <class T, class Container>
|
| 214 |
-
|
| 215 |
-
const queue<T, Container>& y);
|
| 216 |
```
|
| 217 |
|
| 218 |
*Returns:* `x.c > y.c`.
|
| 219 |
|
| 220 |
``` cpp
|
|
@@ -230,11 +265,14 @@ template <class T, class Container>
|
|
| 230 |
``` cpp
|
| 231 |
template <class T, class Container>
|
| 232 |
void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 233 |
```
|
| 234 |
|
| 235 |
-
*
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
### Class template `priority_queue` <a id="priority.queue">[[priority.queue]]</a>
|
| 238 |
|
| 239 |
Any sequence container with random access iterator and supporting
|
| 240 |
operations `front()`, `push_back()` and `pop_back()` can be used to
|
|
@@ -248,15 +286,17 @@ defines a strict weak ordering ([[alg.sorting]]).
|
|
| 248 |
namespace std {
|
| 249 |
template <class T, class Container = vector<T>,
|
| 250 |
class Compare = less<typename Container::value_type>>
|
| 251 |
class priority_queue {
|
| 252 |
public:
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
|
|
|
|
|
|
| 258 |
protected:
|
| 259 |
Container c;
|
| 260 |
Compare comp;
|
| 261 |
|
| 262 |
public:
|
|
@@ -268,29 +308,43 @@ namespace std {
|
|
| 268 |
template <class InputIterator>
|
| 269 |
priority_queue(InputIterator first, InputIterator last,
|
| 270 |
const Compare& x = Compare(), Container&& = Container());
|
| 271 |
template <class Alloc> explicit priority_queue(const Alloc&);
|
| 272 |
template <class Alloc> priority_queue(const Compare&, const Alloc&);
|
| 273 |
-
template <class Alloc> priority_queue(const Compare&,
|
| 274 |
-
|
| 275 |
-
template <class Alloc> priority_queue(const Compare&,
|
| 276 |
-
Container&&, const Alloc&);
|
| 277 |
template <class Alloc> priority_queue(const priority_queue&, const Alloc&);
|
| 278 |
template <class Alloc> priority_queue(priority_queue&&, const Alloc&);
|
| 279 |
|
| 280 |
bool empty() const { return c.empty(); }
|
| 281 |
size_type size() const { return c.size(); }
|
| 282 |
const_reference top() const { return c.front(); }
|
| 283 |
void push(const value_type& x);
|
| 284 |
void push(value_type&& x);
|
| 285 |
template <class... Args> void emplace(Args&&... args);
|
| 286 |
void pop();
|
| 287 |
-
void swap(priority_queue& q) noexcept(
|
| 288 |
-
|
| 289 |
{ using std::swap; swap(c, q.c); swap(comp, q.comp); }
|
| 290 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
// no equality is provided
|
|
|
|
| 292 |
template <class T, class Container, class Compare>
|
| 293 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 294 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 295 |
|
| 296 |
template <class T, class Container, class Compare, class Alloc>
|
|
@@ -300,14 +354,12 @@ namespace std {
|
|
| 300 |
```
|
| 301 |
|
| 302 |
#### `priority_queue` constructors <a id="priqueue.cons">[[priqueue.cons]]</a>
|
| 303 |
|
| 304 |
``` cpp
|
| 305 |
-
priority_queue(const Compare& x,
|
| 306 |
-
|
| 307 |
-
explicit priority_queue(const Compare& x = Compare(),
|
| 308 |
-
Container&& y = Container());
|
| 309 |
```
|
| 310 |
|
| 311 |
*Requires:* `x` shall define a strict weak ordering ([[alg.sorting]]).
|
| 312 |
|
| 313 |
*Effects:* Initializes `comp` with `x` and `c` with `y` (copy
|
|
@@ -332,24 +384,21 @@ constructing or move constructing as appropriate); calls
|
|
| 332 |
`c.insert(c.end(), first, last)`; and finally calls
|
| 333 |
`make_heap(c.begin(), c.end(), comp)`.
|
| 334 |
|
| 335 |
#### `priority_queue` constructors with allocators <a id="priqueue.cons.alloc">[[priqueue.cons.alloc]]</a>
|
| 336 |
|
| 337 |
-
If `
|
| 338 |
-
|
| 339 |
-
resolution.
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
-
template <class Alloc>
|
| 343 |
-
explicit priority_queue(const Alloc& a);
|
| 344 |
```
|
| 345 |
|
| 346 |
*Effects:* Initializes `c` with `a` and value-initializes `comp`.
|
| 347 |
|
| 348 |
``` cpp
|
| 349 |
-
template <class Alloc>
|
| 350 |
-
priority_queue(const Compare& compare, const Alloc& a);
|
| 351 |
```
|
| 352 |
|
| 353 |
*Effects:* Initializes `c` with `a` and initializes `comp` with
|
| 354 |
`compare`.
|
| 355 |
|
|
@@ -357,31 +406,31 @@ template <class Alloc>
|
|
| 357 |
template <class Alloc>
|
| 358 |
priority_queue(const Compare& compare, const Container& cont, const Alloc& a);
|
| 359 |
```
|
| 360 |
|
| 361 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 362 |
-
the second argument, and initializes `comp` with `compare`
|
|
|
|
| 363 |
|
| 364 |
``` cpp
|
| 365 |
template <class Alloc>
|
| 366 |
priority_queue(const Compare& compare, Container&& cont, const Alloc& a);
|
| 367 |
```
|
| 368 |
|
| 369 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 370 |
-
and `a` as the second argument, and initializes `comp` with `compare`
|
|
|
|
| 371 |
|
| 372 |
``` cpp
|
| 373 |
-
template <class Alloc>
|
| 374 |
-
priority_queue(const priority_queue& q, const Alloc& a);
|
| 375 |
```
|
| 376 |
|
| 377 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 378 |
the second argument, and initializes `comp` with `q.comp`.
|
| 379 |
|
| 380 |
``` cpp
|
| 381 |
-
template <class Alloc>
|
| 382 |
-
priority_queue(priority_queue&& q, const Alloc& a);
|
| 383 |
```
|
| 384 |
|
| 385 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 386 |
and `a` as the second argument, and initializes `comp` with
|
| 387 |
`std::move(q.comp)`.
|
|
@@ -390,104 +439,84 @@ and `a` as the second argument, and initializes `comp` with
|
|
| 390 |
|
| 391 |
``` cpp
|
| 392 |
void push(const value_type& x);
|
| 393 |
```
|
| 394 |
|
| 395 |
-
*Effects:*
|
| 396 |
|
| 397 |
``` cpp
|
| 398 |
c.push_back(x);
|
| 399 |
push_heap(c.begin(), c.end(), comp);
|
| 400 |
```
|
| 401 |
|
| 402 |
``` cpp
|
| 403 |
void push(value_type&& x);
|
| 404 |
```
|
| 405 |
|
| 406 |
-
*Effects:*
|
| 407 |
|
| 408 |
``` cpp
|
| 409 |
c.push_back(std::move(x));
|
| 410 |
push_heap(c.begin(), c.end(), comp);
|
| 411 |
```
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
template <class... Args> void emplace(Args&&... args)
|
| 415 |
```
|
| 416 |
|
| 417 |
-
*Effects:*
|
| 418 |
|
| 419 |
``` cpp
|
| 420 |
c.emplace_back(std::forward<Args>(args)...);
|
| 421 |
push_heap(c.begin(), c.end(), comp);
|
| 422 |
```
|
| 423 |
|
| 424 |
``` cpp
|
| 425 |
void pop();
|
| 426 |
```
|
| 427 |
|
| 428 |
-
*Effects:*
|
| 429 |
|
| 430 |
``` cpp
|
| 431 |
pop_heap(c.begin(), c.end(), comp);
|
| 432 |
c.pop_back();
|
| 433 |
```
|
| 434 |
|
| 435 |
#### `priority_queue` specialized algorithms <a id="priqueue.special">[[priqueue.special]]</a>
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
-
template <class T, class Container, Compare>
|
| 439 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 440 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 441 |
```
|
| 442 |
|
| 443 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
|
| 445 |
### Class template `stack` <a id="stack">[[stack]]</a>
|
| 446 |
|
| 447 |
Any sequence container supporting operations `back()`, `push_back()` and
|
| 448 |
`pop_back()` can be used to instantiate `stack`. In particular,
|
| 449 |
`vector` ([[vector]]), `list` ([[list]]) and `deque` ([[deque]]) can
|
| 450 |
be used.
|
| 451 |
|
| 452 |
-
#### Header `<stack>` synopsis <a id="stack.syn">[[stack.syn]]</a>
|
| 453 |
-
|
| 454 |
-
``` cpp
|
| 455 |
-
#include <initializer_list>
|
| 456 |
-
|
| 457 |
-
namespace std {
|
| 458 |
-
|
| 459 |
-
template <class T, class Container = deque<T> > class stack;
|
| 460 |
-
template <class T, class Container>
|
| 461 |
-
bool operator==(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 462 |
-
template <class T, class Container>
|
| 463 |
-
bool operator< (const stack<T, Container>& x,const stack<T, Container>& y);
|
| 464 |
-
template <class T, class Container>
|
| 465 |
-
bool operator!=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 466 |
-
template <class T, class Container>
|
| 467 |
-
bool operator> (const stack<T, Container>& x,const stack<T, Container>& y);
|
| 468 |
-
template <class T, class Container>
|
| 469 |
-
bool operator>=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 470 |
-
template <class T, class Container>
|
| 471 |
-
bool operator<=(const stack<T, Container>& x,const stack<T, Container>& y);
|
| 472 |
-
template <class T, class Container>
|
| 473 |
-
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 474 |
-
}
|
| 475 |
-
```
|
| 476 |
-
|
| 477 |
#### `stack` definition <a id="stack.defn">[[stack.defn]]</a>
|
| 478 |
|
| 479 |
``` cpp
|
| 480 |
namespace std {
|
| 481 |
template <class T, class Container = deque<T>>
|
| 482 |
class stack {
|
| 483 |
public:
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
|
|
|
| 489 |
protected:
|
| 490 |
Container c;
|
| 491 |
|
| 492 |
public:
|
| 493 |
explicit stack(const Container&);
|
|
@@ -502,17 +531,23 @@ namespace std {
|
|
| 502 |
size_type size() const { return c.size(); }
|
| 503 |
reference top() { return c.back(); }
|
| 504 |
const_reference top() const { return c.back(); }
|
| 505 |
void push(const value_type& x) { c.push_back(x); }
|
| 506 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 507 |
-
template <class... Args>
|
| 508 |
-
{ c.emplace_back(std::forward<Args>(args)...); }
|
| 509 |
void pop() { c.pop_back(); }
|
| 510 |
-
void swap(stack& s) noexcept(
|
| 511 |
{ using std::swap; swap(c, s.c); }
|
| 512 |
};
|
| 513 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 514 |
template <class T, class Container>
|
| 515 |
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 516 |
template <class T, class Container>
|
| 517 |
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 518 |
template <class T, class Container>
|
|
@@ -546,99 +581,87 @@ explicit stack(Container&& cont = Container());
|
|
| 546 |
|
| 547 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 548 |
|
| 549 |
#### `stack` constructors with allocators <a id="stack.cons.alloc">[[stack.cons.alloc]]</a>
|
| 550 |
|
| 551 |
-
If `
|
| 552 |
-
|
| 553 |
-
resolution.
|
| 554 |
|
| 555 |
``` cpp
|
| 556 |
-
template <class Alloc>
|
| 557 |
-
explicit stack(const Alloc& a);
|
| 558 |
```
|
| 559 |
|
| 560 |
*Effects:* Initializes `c` with `a`.
|
| 561 |
|
| 562 |
``` cpp
|
| 563 |
-
template <class Alloc>
|
| 564 |
-
stack(const container_type& cont, const Alloc& a);
|
| 565 |
```
|
| 566 |
|
| 567 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 568 |
the second argument.
|
| 569 |
|
| 570 |
``` cpp
|
| 571 |
-
template <class Alloc>
|
| 572 |
-
stack(container_type&& cont, const Alloc& a);
|
| 573 |
```
|
| 574 |
|
| 575 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 576 |
and `a` as the second argument.
|
| 577 |
|
| 578 |
``` cpp
|
| 579 |
-
template <class Alloc>
|
| 580 |
-
stack(const stack& s, const Alloc& a);
|
| 581 |
```
|
| 582 |
|
| 583 |
*Effects:* Initializes `c` with `s.c` as the first argument and `a` as
|
| 584 |
the second argument.
|
| 585 |
|
| 586 |
``` cpp
|
| 587 |
-
template <class Alloc>
|
| 588 |
-
stack(stack&& s, const Alloc& a);
|
| 589 |
```
|
| 590 |
|
| 591 |
*Effects:* Initializes `c` with `std::move(s.c)` as the first argument
|
| 592 |
and `a` as the second argument.
|
| 593 |
|
| 594 |
#### `stack` operators <a id="stack.ops">[[stack.ops]]</a>
|
| 595 |
|
| 596 |
``` cpp
|
| 597 |
template <class T, class Container>
|
| 598 |
-
|
| 599 |
-
const stack<T, Container>& y);
|
| 600 |
```
|
| 601 |
|
| 602 |
*Returns:* `x.c == y.c`.
|
| 603 |
|
| 604 |
``` cpp
|
| 605 |
template <class T, class Container>
|
| 606 |
-
|
| 607 |
-
const stack<T, Container>& y);
|
| 608 |
```
|
| 609 |
|
| 610 |
*Returns:* `x.c != y.c`.
|
| 611 |
|
| 612 |
``` cpp
|
| 613 |
template <class T, class Container>
|
| 614 |
-
|
| 615 |
-
const stack<T, Container>& y);
|
| 616 |
```
|
| 617 |
|
| 618 |
*Returns:* `x.c < y.c`.
|
| 619 |
|
| 620 |
``` cpp
|
| 621 |
template <class T, class Container>
|
| 622 |
-
|
| 623 |
-
const stack<T, Container>& y);
|
| 624 |
```
|
| 625 |
|
| 626 |
*Returns:* `x.c <= y.c`.
|
| 627 |
|
| 628 |
``` cpp
|
| 629 |
template <class T, class Container>
|
| 630 |
-
|
| 631 |
-
const stack<T, Container>& y);
|
| 632 |
```
|
| 633 |
|
| 634 |
*Returns:* `x.c > y.c`.
|
| 635 |
|
| 636 |
``` cpp
|
| 637 |
template <class T, class Container>
|
| 638 |
-
bool operator>=(const stack<T, Container>& x,
|
| 639 |
-
const stack<T, Container>& y);
|
| 640 |
```
|
| 641 |
|
| 642 |
*Returns:* `x.c >= y.c`.
|
| 643 |
|
| 644 |
#### `stack` specialized algorithms <a id="stack.special">[[stack.special]]</a>
|
|
@@ -646,26 +669,31 @@ template <class T, class Container>
|
|
| 646 |
``` cpp
|
| 647 |
template <class T, class Container>
|
| 648 |
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 649 |
```
|
| 650 |
|
| 651 |
-
*
|
|
|
|
|
|
|
|
|
|
| 652 |
|
| 653 |
<!-- Link reference definitions -->
|
| 654 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 655 |
[algorithm.stable]: library.md#algorithm.stable
|
| 656 |
[algorithms]: algorithms.md#algorithms
|
| 657 |
[allocator.requirements]: library.md#allocator.requirements
|
|
|
|
| 658 |
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 659 |
[array]: #array
|
| 660 |
[array.cons]: #array.cons
|
| 661 |
[array.data]: #array.data
|
| 662 |
[array.fill]: #array.fill
|
| 663 |
[array.overview]: #array.overview
|
| 664 |
[array.size]: #array.size
|
| 665 |
[array.special]: #array.special
|
| 666 |
[array.swap]: #array.swap
|
|
|
|
| 667 |
[array.tuple]: #array.tuple
|
| 668 |
[array.zero]: #array.zero
|
| 669 |
[associative]: #associative
|
| 670 |
[associative.general]: #associative.general
|
| 671 |
[associative.map.syn]: #associative.map.syn
|
|
@@ -676,10 +704,17 @@ template <class T, class Container>
|
|
| 676 |
[class.copy]: special.md#class.copy
|
| 677 |
[class.ctor]: special.md#class.ctor
|
| 678 |
[class.dtor]: special.md#class.dtor
|
| 679 |
[container.adaptors]: #container.adaptors
|
| 680 |
[container.adaptors.general]: #container.adaptors.general
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
[container.requirements]: #container.requirements
|
| 682 |
[container.requirements.dataraces]: #container.requirements.dataraces
|
| 683 |
[container.requirements.general]: #container.requirements.general
|
| 684 |
[containers]: #containers
|
| 685 |
[containers.general]: #containers.general
|
|
@@ -688,28 +723,32 @@ template <class T, class Container>
|
|
| 688 |
[deque.capacity]: #deque.capacity
|
| 689 |
[deque.cons]: #deque.cons
|
| 690 |
[deque.modifiers]: #deque.modifiers
|
| 691 |
[deque.overview]: #deque.overview
|
| 692 |
[deque.special]: #deque.special
|
|
|
|
| 693 |
[forward.iterators]: iterators.md#forward.iterators
|
|
|
|
| 694 |
[forwardlist]: #forwardlist
|
| 695 |
[forwardlist.access]: #forwardlist.access
|
| 696 |
[forwardlist.cons]: #forwardlist.cons
|
| 697 |
[forwardlist.iter]: #forwardlist.iter
|
| 698 |
[forwardlist.modifiers]: #forwardlist.modifiers
|
| 699 |
[forwardlist.ops]: #forwardlist.ops
|
| 700 |
[forwardlist.overview]: #forwardlist.overview
|
| 701 |
[forwardlist.spec]: #forwardlist.spec
|
| 702 |
[hash.requirements]: library.md#hash.requirements
|
| 703 |
[iterator.requirements]: iterators.md#iterator.requirements
|
|
|
|
| 704 |
[list]: #list
|
| 705 |
[list.capacity]: #list.capacity
|
| 706 |
[list.cons]: #list.cons
|
| 707 |
[list.modifiers]: #list.modifiers
|
| 708 |
[list.ops]: #list.ops
|
| 709 |
[list.overview]: #list.overview
|
| 710 |
[list.special]: #list.special
|
|
|
|
| 711 |
[map]: #map
|
| 712 |
[map.access]: #map.access
|
| 713 |
[map.cons]: #map.cons
|
| 714 |
[map.modifiers]: #map.modifiers
|
| 715 |
[map.overview]: #map.overview
|
|
@@ -733,10 +772,11 @@ template <class T, class Container>
|
|
| 733 |
[queue.cons.alloc]: #queue.cons.alloc
|
| 734 |
[queue.defn]: #queue.defn
|
| 735 |
[queue.ops]: #queue.ops
|
| 736 |
[queue.special]: #queue.special
|
| 737 |
[queue.syn]: #queue.syn
|
|
|
|
| 738 |
[res.on.data.races]: library.md#res.on.data.races
|
| 739 |
[sequence.reqmts]: #sequence.reqmts
|
| 740 |
[sequences]: #sequences
|
| 741 |
[sequences.general]: #sequences.general
|
| 742 |
[set]: #set
|
|
@@ -749,15 +789,17 @@ template <class T, class Container>
|
|
| 749 |
[stack.defn]: #stack.defn
|
| 750 |
[stack.ops]: #stack.ops
|
| 751 |
[stack.special]: #stack.special
|
| 752 |
[stack.syn]: #stack.syn
|
| 753 |
[strings]: strings.md#strings
|
|
|
|
| 754 |
[tab:HashRequirements]: #tab:HashRequirements
|
| 755 |
[tab:containers.allocatoraware]: #tab:containers.allocatoraware
|
| 756 |
[tab:containers.associative.requirements]: #tab:containers.associative.requirements
|
| 757 |
[tab:containers.container.requirements]: #tab:containers.container.requirements
|
| 758 |
[tab:containers.lib.summary]: #tab:containers.lib.summary
|
|
|
|
| 759 |
[tab:containers.optional.operations]: #tab:containers.optional.operations
|
| 760 |
[tab:containers.reversible.requirements]: #tab:containers.reversible.requirements
|
| 761 |
[tab:containers.sequence.optional]: #tab:containers.sequence.optional
|
| 762 |
[tab:containers.sequence.requirements]: #tab:containers.sequence.requirements
|
| 763 |
[temp.deduct]: temp.md#temp.deduct
|
|
@@ -793,10 +835,11 @@ template <class T, class Container>
|
|
| 793 |
[vector.cons]: #vector.cons
|
| 794 |
[vector.data]: #vector.data
|
| 795 |
[vector.modifiers]: #vector.modifiers
|
| 796 |
[vector.overview]: #vector.overview
|
| 797 |
[vector.special]: #vector.special
|
|
|
|
| 798 |
|
| 799 |
[^1]: Equality comparison is a refinement of partitioning if no two
|
| 800 |
objects that compare equal fall into different partitions.
|
| 801 |
|
| 802 |
[^2]: These member functions are only provided by containers whose
|
|
|
|
| 8 |
The container adaptors each take a `Container` template parameter, and
|
| 9 |
each constructor takes a `Container` reference argument. This container
|
| 10 |
is copied into the `Container` member of each adaptor. If the container
|
| 11 |
takes an allocator, then a compatible allocator may be passed in to the
|
| 12 |
adaptor’s constructor. Otherwise, normal copy or move construction is
|
| 13 |
+
used for the container argument. The first template parameter `T` of the
|
| 14 |
+
container adaptors shall denote the same type as
|
| 15 |
+
`Container::value_type`.
|
| 16 |
|
| 17 |
For container adaptors, no `swap` function throws an exception unless
|
| 18 |
that exception is thrown by the swap of the adaptor’s `Container` or
|
| 19 |
`Compare` object (if any).
|
| 20 |
|
| 21 |
+
A deduction guide for a container adaptor shall not participate in
|
| 22 |
+
overload resolution if any of the following are true:
|
| 23 |
+
|
| 24 |
+
- It has an `InputIterator` template parameter and a type that does not
|
| 25 |
+
qualify as an input iterator is deduced for that parameter.
|
| 26 |
+
- It has a `Compare` template parameter and a type that qualifies as an
|
| 27 |
+
allocator is deduced for that parameter.
|
| 28 |
+
- It has a `Container` template parameter and a type that qualifies as
|
| 29 |
+
an allocator is deduced for that parameter.
|
| 30 |
+
- It has an `Allocator` template parameter and a type that does not
|
| 31 |
+
qualify as an allocator is deduced for that parameter.
|
| 32 |
+
- It has both `Container` and `Allocator` template parameters, and
|
| 33 |
+
`uses_allocator_v<Container, Allocator>` is `false`.
|
| 34 |
+
|
| 35 |
### Header `<queue>` synopsis <a id="queue.syn">[[queue.syn]]</a>
|
| 36 |
|
| 37 |
``` cpp
|
| 38 |
#include <initializer_list>
|
| 39 |
|
| 40 |
namespace std {
|
|
|
|
| 41 |
template <class T, class Container = deque<T>> class queue;
|
| 42 |
template <class T, class Container = vector<T>,
|
| 43 |
class Compare = less<typename Container::value_type>>
|
| 44 |
class priority_queue;
|
| 45 |
|
|
|
|
| 62 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 63 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 64 |
}
|
| 65 |
```
|
| 66 |
|
| 67 |
+
### Header `<stack>` synopsis <a id="stack.syn">[[stack.syn]]</a>
|
| 68 |
+
|
| 69 |
+
``` cpp
|
| 70 |
+
#include <initializer_list>
|
| 71 |
+
|
| 72 |
+
namespace std {
|
| 73 |
+
template <class T, class Container = deque<T>> class stack;
|
| 74 |
+
template <class T, class Container>
|
| 75 |
+
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 76 |
+
template <class T, class Container>
|
| 77 |
+
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 78 |
+
template <class T, class Container>
|
| 79 |
+
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 80 |
+
template <class T, class Container>
|
| 81 |
+
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 82 |
+
template <class T, class Container>
|
| 83 |
+
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 84 |
+
template <class T, class Container>
|
| 85 |
+
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 86 |
+
template <class T, class Container>
|
| 87 |
+
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 88 |
+
}
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
### Class template `queue` <a id="queue">[[queue]]</a>
|
| 92 |
|
| 93 |
#### `queue` definition <a id="queue.defn">[[queue.defn]]</a>
|
| 94 |
|
| 95 |
Any sequence container supporting operations `front()`, `back()`,
|
|
|
|
| 99 |
``` cpp
|
| 100 |
namespace std {
|
| 101 |
template <class T, class Container = deque<T>>
|
| 102 |
class queue {
|
| 103 |
public:
|
| 104 |
+
using value_type = typename Container::value_type;
|
| 105 |
+
using reference = typename Container::reference;
|
| 106 |
+
using const_reference = typename Container::const_reference;
|
| 107 |
+
using size_type = typename Container::size_type;
|
| 108 |
+
using container_type = Container;
|
| 109 |
+
|
| 110 |
protected:
|
| 111 |
Container c;
|
| 112 |
|
| 113 |
public:
|
| 114 |
explicit queue(const Container&);
|
|
|
|
| 125 |
const_reference front() const { return c.front(); }
|
| 126 |
reference back() { return c.back(); }
|
| 127 |
const_reference back() const { return c.back(); }
|
| 128 |
void push(const value_type& x) { c.push_back(x); }
|
| 129 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 130 |
+
template <class... Args>
|
| 131 |
+
reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
|
| 132 |
void pop() { c.pop_front(); }
|
| 133 |
+
void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
|
| 134 |
{ using std::swap; swap(c, q.c); }
|
| 135 |
};
|
| 136 |
|
| 137 |
+
template<class Container>
|
| 138 |
+
queue(Container) -> queue<typename Container::value_type, Container>;
|
| 139 |
+
|
| 140 |
+
template<class Container, class Allocator>
|
| 141 |
+
queue(Container, Allocator) -> queue<typename Container::value_type, Container>;
|
| 142 |
+
|
| 143 |
template <class T, class Container>
|
| 144 |
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
| 145 |
template <class T, class Container>
|
| 146 |
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
| 147 |
template <class T, class Container>
|
|
|
|
| 176 |
|
| 177 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 178 |
|
| 179 |
#### `queue` constructors with allocators <a id="queue.cons.alloc">[[queue.cons.alloc]]</a>
|
| 180 |
|
| 181 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 182 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 183 |
|
| 184 |
``` cpp
|
| 185 |
+
template <class Alloc> explicit queue(const Alloc& a);
|
|
|
|
| 186 |
```
|
| 187 |
|
| 188 |
*Effects:* Initializes `c` with `a`.
|
| 189 |
|
| 190 |
``` cpp
|
| 191 |
+
template <class Alloc> queue(const container_type& cont, const Alloc& a);
|
|
|
|
| 192 |
```
|
| 193 |
|
| 194 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 195 |
the second argument.
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
+
template <class Alloc> queue(container_type&& cont, const Alloc& a);
|
|
|
|
| 199 |
```
|
| 200 |
|
| 201 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 202 |
and `a` as the second argument.
|
| 203 |
|
| 204 |
``` cpp
|
| 205 |
+
template <class Alloc> queue(const queue& q, const Alloc& a);
|
|
|
|
| 206 |
```
|
| 207 |
|
| 208 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 209 |
the second argument.
|
| 210 |
|
| 211 |
``` cpp
|
| 212 |
+
template <class Alloc> queue(queue&& q, const Alloc& a);
|
|
|
|
| 213 |
```
|
| 214 |
|
| 215 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 216 |
and `a` as the second argument.
|
| 217 |
|
| 218 |
#### `queue` operators <a id="queue.ops">[[queue.ops]]</a>
|
| 219 |
|
| 220 |
``` cpp
|
| 221 |
template <class T, class Container>
|
| 222 |
+
bool operator==(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 223 |
```
|
| 224 |
|
| 225 |
*Returns:* `x.c == y.c`.
|
| 226 |
|
| 227 |
``` cpp
|
| 228 |
template <class T, class Container>
|
| 229 |
+
bool operator!=(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 230 |
```
|
| 231 |
|
| 232 |
*Returns:* `x.c != y.c`.
|
| 233 |
|
| 234 |
``` cpp
|
| 235 |
template <class T, class Container>
|
| 236 |
+
bool operator< (const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 237 |
```
|
| 238 |
|
| 239 |
*Returns:* `x.c < y.c`.
|
| 240 |
|
| 241 |
``` cpp
|
| 242 |
template <class T, class Container>
|
| 243 |
+
bool operator<=(const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 244 |
```
|
| 245 |
|
| 246 |
*Returns:* `x.c <= y.c`.
|
| 247 |
|
| 248 |
``` cpp
|
| 249 |
template <class T, class Container>
|
| 250 |
+
bool operator> (const queue<T, Container>& x, const queue<T, Container>& y);
|
|
|
|
| 251 |
```
|
| 252 |
|
| 253 |
*Returns:* `x.c > y.c`.
|
| 254 |
|
| 255 |
``` cpp
|
|
|
|
| 265 |
``` cpp
|
| 266 |
template <class T, class Container>
|
| 267 |
void swap(queue<T, Container>& x, queue<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 268 |
```
|
| 269 |
|
| 270 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 271 |
+
unless `is_swappable_v<Container>` is `true`.
|
| 272 |
+
|
| 273 |
+
*Effects:* As if by `x.swap(y)`.
|
| 274 |
|
| 275 |
### Class template `priority_queue` <a id="priority.queue">[[priority.queue]]</a>
|
| 276 |
|
| 277 |
Any sequence container with random access iterator and supporting
|
| 278 |
operations `front()`, `push_back()` and `pop_back()` can be used to
|
|
|
|
| 286 |
namespace std {
|
| 287 |
template <class T, class Container = vector<T>,
|
| 288 |
class Compare = less<typename Container::value_type>>
|
| 289 |
class priority_queue {
|
| 290 |
public:
|
| 291 |
+
using value_type = typename Container::value_type;
|
| 292 |
+
using reference = typename Container::reference;
|
| 293 |
+
using const_reference = typename Container::const_reference;
|
| 294 |
+
using size_type = typename Container::size_type;
|
| 295 |
+
using container_type = Container;
|
| 296 |
+
using value_compare = Compare;
|
| 297 |
+
|
| 298 |
protected:
|
| 299 |
Container c;
|
| 300 |
Compare comp;
|
| 301 |
|
| 302 |
public:
|
|
|
|
| 308 |
template <class InputIterator>
|
| 309 |
priority_queue(InputIterator first, InputIterator last,
|
| 310 |
const Compare& x = Compare(), Container&& = Container());
|
| 311 |
template <class Alloc> explicit priority_queue(const Alloc&);
|
| 312 |
template <class Alloc> priority_queue(const Compare&, const Alloc&);
|
| 313 |
+
template <class Alloc> priority_queue(const Compare&, const Container&, const Alloc&);
|
| 314 |
+
template <class Alloc> priority_queue(const Compare&, Container&&, const Alloc&);
|
|
|
|
|
|
|
| 315 |
template <class Alloc> priority_queue(const priority_queue&, const Alloc&);
|
| 316 |
template <class Alloc> priority_queue(priority_queue&&, const Alloc&);
|
| 317 |
|
| 318 |
bool empty() const { return c.empty(); }
|
| 319 |
size_type size() const { return c.size(); }
|
| 320 |
const_reference top() const { return c.front(); }
|
| 321 |
void push(const value_type& x);
|
| 322 |
void push(value_type&& x);
|
| 323 |
template <class... Args> void emplace(Args&&... args);
|
| 324 |
void pop();
|
| 325 |
+
void swap(priority_queue& q) noexcept(is_nothrow_swappable_v<Container> &&
|
| 326 |
+
is_nothrow_swappable_v<Compare>)
|
| 327 |
{ using std::swap; swap(c, q.c); swap(comp, q.comp); }
|
| 328 |
};
|
| 329 |
+
|
| 330 |
+
template<class Compare, class Container>
|
| 331 |
+
priority_queue(Compare, Container)
|
| 332 |
+
-> priority_queue<typename Container::value_type, Container, Compare>;
|
| 333 |
+
|
| 334 |
+
template<class InputIterator,
|
| 335 |
+
class Compare = less<typename iterator_traits<InputIterator>::value_type>,
|
| 336 |
+
class Container = vector<typename iterator_traits<InputIterator>::value_type>>
|
| 337 |
+
priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
|
| 338 |
+
-> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>;
|
| 339 |
+
|
| 340 |
+
template<class Compare, class Container, class Allocator>
|
| 341 |
+
priority_queue(Compare, Container, Allocator)
|
| 342 |
+
-> priority_queue<typename Container::value_type, Container, Compare>;
|
| 343 |
+
|
| 344 |
// no equality is provided
|
| 345 |
+
|
| 346 |
template <class T, class Container, class Compare>
|
| 347 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 348 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 349 |
|
| 350 |
template <class T, class Container, class Compare, class Alloc>
|
|
|
|
| 354 |
```
|
| 355 |
|
| 356 |
#### `priority_queue` constructors <a id="priqueue.cons">[[priqueue.cons]]</a>
|
| 357 |
|
| 358 |
``` cpp
|
| 359 |
+
priority_queue(const Compare& x, const Container& y);
|
| 360 |
+
explicit priority_queue(const Compare& x = Compare(), Container&& y = Container());
|
|
|
|
|
|
|
| 361 |
```
|
| 362 |
|
| 363 |
*Requires:* `x` shall define a strict weak ordering ([[alg.sorting]]).
|
| 364 |
|
| 365 |
*Effects:* Initializes `comp` with `x` and `c` with `y` (copy
|
|
|
|
| 384 |
`c.insert(c.end(), first, last)`; and finally calls
|
| 385 |
`make_heap(c.begin(), c.end(), comp)`.
|
| 386 |
|
| 387 |
#### `priority_queue` constructors with allocators <a id="priqueue.cons.alloc">[[priqueue.cons.alloc]]</a>
|
| 388 |
|
| 389 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 390 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 391 |
|
| 392 |
``` cpp
|
| 393 |
+
template <class Alloc> explicit priority_queue(const Alloc& a);
|
|
|
|
| 394 |
```
|
| 395 |
|
| 396 |
*Effects:* Initializes `c` with `a` and value-initializes `comp`.
|
| 397 |
|
| 398 |
``` cpp
|
| 399 |
+
template <class Alloc> priority_queue(const Compare& compare, const Alloc& a);
|
|
|
|
| 400 |
```
|
| 401 |
|
| 402 |
*Effects:* Initializes `c` with `a` and initializes `comp` with
|
| 403 |
`compare`.
|
| 404 |
|
|
|
|
| 406 |
template <class Alloc>
|
| 407 |
priority_queue(const Compare& compare, const Container& cont, const Alloc& a);
|
| 408 |
```
|
| 409 |
|
| 410 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 411 |
+
the second argument, and initializes `comp` with `compare`; calls
|
| 412 |
+
`make_heap(c.begin(), c.end(), comp)`.
|
| 413 |
|
| 414 |
``` cpp
|
| 415 |
template <class Alloc>
|
| 416 |
priority_queue(const Compare& compare, Container&& cont, const Alloc& a);
|
| 417 |
```
|
| 418 |
|
| 419 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 420 |
+
and `a` as the second argument, and initializes `comp` with `compare`;
|
| 421 |
+
calls `make_heap(c.begin(), c.end(), comp)`.
|
| 422 |
|
| 423 |
``` cpp
|
| 424 |
+
template <class Alloc> priority_queue(const priority_queue& q, const Alloc& a);
|
|
|
|
| 425 |
```
|
| 426 |
|
| 427 |
*Effects:* Initializes `c` with `q.c` as the first argument and `a` as
|
| 428 |
the second argument, and initializes `comp` with `q.comp`.
|
| 429 |
|
| 430 |
``` cpp
|
| 431 |
+
template <class Alloc> priority_queue(priority_queue&& q, const Alloc& a);
|
|
|
|
| 432 |
```
|
| 433 |
|
| 434 |
*Effects:* Initializes `c` with `std::move(q.c)` as the first argument
|
| 435 |
and `a` as the second argument, and initializes `comp` with
|
| 436 |
`std::move(q.comp)`.
|
|
|
|
| 439 |
|
| 440 |
``` cpp
|
| 441 |
void push(const value_type& x);
|
| 442 |
```
|
| 443 |
|
| 444 |
+
*Effects:* As if by:
|
| 445 |
|
| 446 |
``` cpp
|
| 447 |
c.push_back(x);
|
| 448 |
push_heap(c.begin(), c.end(), comp);
|
| 449 |
```
|
| 450 |
|
| 451 |
``` cpp
|
| 452 |
void push(value_type&& x);
|
| 453 |
```
|
| 454 |
|
| 455 |
+
*Effects:* As if by:
|
| 456 |
|
| 457 |
``` cpp
|
| 458 |
c.push_back(std::move(x));
|
| 459 |
push_heap(c.begin(), c.end(), comp);
|
| 460 |
```
|
| 461 |
|
| 462 |
``` cpp
|
| 463 |
template <class... Args> void emplace(Args&&... args)
|
| 464 |
```
|
| 465 |
|
| 466 |
+
*Effects:* As if by:
|
| 467 |
|
| 468 |
``` cpp
|
| 469 |
c.emplace_back(std::forward<Args>(args)...);
|
| 470 |
push_heap(c.begin(), c.end(), comp);
|
| 471 |
```
|
| 472 |
|
| 473 |
``` cpp
|
| 474 |
void pop();
|
| 475 |
```
|
| 476 |
|
| 477 |
+
*Effects:* As if by:
|
| 478 |
|
| 479 |
``` cpp
|
| 480 |
pop_heap(c.begin(), c.end(), comp);
|
| 481 |
c.pop_back();
|
| 482 |
```
|
| 483 |
|
| 484 |
#### `priority_queue` specialized algorithms <a id="priqueue.special">[[priqueue.special]]</a>
|
| 485 |
|
| 486 |
``` cpp
|
| 487 |
+
template <class T, class Container, class Compare>
|
| 488 |
void swap(priority_queue<T, Container, Compare>& x,
|
| 489 |
priority_queue<T, Container, Compare>& y) noexcept(noexcept(x.swap(y)));
|
| 490 |
```
|
| 491 |
|
| 492 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 493 |
+
unless `is_swappable_v<Container>` is `true` and
|
| 494 |
+
`is_swappable_v<Compare>` is `true`.
|
| 495 |
+
|
| 496 |
+
*Effects:* As if by `x.swap(y)`.
|
| 497 |
|
| 498 |
### Class template `stack` <a id="stack">[[stack]]</a>
|
| 499 |
|
| 500 |
Any sequence container supporting operations `back()`, `push_back()` and
|
| 501 |
`pop_back()` can be used to instantiate `stack`. In particular,
|
| 502 |
`vector` ([[vector]]), `list` ([[list]]) and `deque` ([[deque]]) can
|
| 503 |
be used.
|
| 504 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
#### `stack` definition <a id="stack.defn">[[stack.defn]]</a>
|
| 506 |
|
| 507 |
``` cpp
|
| 508 |
namespace std {
|
| 509 |
template <class T, class Container = deque<T>>
|
| 510 |
class stack {
|
| 511 |
public:
|
| 512 |
+
using value_type = typename Container::value_type;
|
| 513 |
+
using reference = typename Container::reference;
|
| 514 |
+
using const_reference = typename Container::const_reference;
|
| 515 |
+
using size_type = typename Container::size_type;
|
| 516 |
+
using container_type = Container;
|
| 517 |
+
|
| 518 |
protected:
|
| 519 |
Container c;
|
| 520 |
|
| 521 |
public:
|
| 522 |
explicit stack(const Container&);
|
|
|
|
| 531 |
size_type size() const { return c.size(); }
|
| 532 |
reference top() { return c.back(); }
|
| 533 |
const_reference top() const { return c.back(); }
|
| 534 |
void push(const value_type& x) { c.push_back(x); }
|
| 535 |
void push(value_type&& x) { c.push_back(std::move(x)); }
|
| 536 |
+
template <class... Args>
|
| 537 |
+
reference emplace(Args&&... args) { return c.emplace_back(std::forward<Args>(args)...); }
|
| 538 |
void pop() { c.pop_back(); }
|
| 539 |
+
void swap(stack& s) noexcept(is_nothrow_swappable_v<Container>)
|
| 540 |
{ using std::swap; swap(c, s.c); }
|
| 541 |
};
|
| 542 |
|
| 543 |
+
template<class Container>
|
| 544 |
+
stack(Container) -> stack<typename Container::value_type, Container>;
|
| 545 |
+
|
| 546 |
+
template<class Container, class Allocator>
|
| 547 |
+
stack(Container, Allocator) -> stack<typename Container::value_type, Container>;
|
| 548 |
+
|
| 549 |
template <class T, class Container>
|
| 550 |
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
| 551 |
template <class T, class Container>
|
| 552 |
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
| 553 |
template <class T, class Container>
|
|
|
|
| 581 |
|
| 582 |
*Effects:* Initializes `c` with `std::move(cont)`.
|
| 583 |
|
| 584 |
#### `stack` constructors with allocators <a id="stack.cons.alloc">[[stack.cons.alloc]]</a>
|
| 585 |
|
| 586 |
+
If `uses_allocator_v<container_type, Alloc>` is `false` the constructors
|
| 587 |
+
in this subclause shall not participate in overload resolution.
|
|
|
|
| 588 |
|
| 589 |
``` cpp
|
| 590 |
+
template <class Alloc> explicit stack(const Alloc& a);
|
|
|
|
| 591 |
```
|
| 592 |
|
| 593 |
*Effects:* Initializes `c` with `a`.
|
| 594 |
|
| 595 |
``` cpp
|
| 596 |
+
template <class Alloc> stack(const container_type& cont, const Alloc& a);
|
|
|
|
| 597 |
```
|
| 598 |
|
| 599 |
*Effects:* Initializes `c` with `cont` as the first argument and `a` as
|
| 600 |
the second argument.
|
| 601 |
|
| 602 |
``` cpp
|
| 603 |
+
template <class Alloc> stack(container_type&& cont, const Alloc& a);
|
|
|
|
| 604 |
```
|
| 605 |
|
| 606 |
*Effects:* Initializes `c` with `std::move(cont)` as the first argument
|
| 607 |
and `a` as the second argument.
|
| 608 |
|
| 609 |
``` cpp
|
| 610 |
+
template <class Alloc> stack(const stack& s, const Alloc& a);
|
|
|
|
| 611 |
```
|
| 612 |
|
| 613 |
*Effects:* Initializes `c` with `s.c` as the first argument and `a` as
|
| 614 |
the second argument.
|
| 615 |
|
| 616 |
``` cpp
|
| 617 |
+
template <class Alloc> stack(stack&& s, const Alloc& a);
|
|
|
|
| 618 |
```
|
| 619 |
|
| 620 |
*Effects:* Initializes `c` with `std::move(s.c)` as the first argument
|
| 621 |
and `a` as the second argument.
|
| 622 |
|
| 623 |
#### `stack` operators <a id="stack.ops">[[stack.ops]]</a>
|
| 624 |
|
| 625 |
``` cpp
|
| 626 |
template <class T, class Container>
|
| 627 |
+
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 628 |
```
|
| 629 |
|
| 630 |
*Returns:* `x.c == y.c`.
|
| 631 |
|
| 632 |
``` cpp
|
| 633 |
template <class T, class Container>
|
| 634 |
+
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 635 |
```
|
| 636 |
|
| 637 |
*Returns:* `x.c != y.c`.
|
| 638 |
|
| 639 |
``` cpp
|
| 640 |
template <class T, class Container>
|
| 641 |
+
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 642 |
```
|
| 643 |
|
| 644 |
*Returns:* `x.c < y.c`.
|
| 645 |
|
| 646 |
``` cpp
|
| 647 |
template <class T, class Container>
|
| 648 |
+
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 649 |
```
|
| 650 |
|
| 651 |
*Returns:* `x.c <= y.c`.
|
| 652 |
|
| 653 |
``` cpp
|
| 654 |
template <class T, class Container>
|
| 655 |
+
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 656 |
```
|
| 657 |
|
| 658 |
*Returns:* `x.c > y.c`.
|
| 659 |
|
| 660 |
``` cpp
|
| 661 |
template <class T, class Container>
|
| 662 |
+
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
|
|
|
|
| 663 |
```
|
| 664 |
|
| 665 |
*Returns:* `x.c >= y.c`.
|
| 666 |
|
| 667 |
#### `stack` specialized algorithms <a id="stack.special">[[stack.special]]</a>
|
|
|
|
| 669 |
``` cpp
|
| 670 |
template <class T, class Container>
|
| 671 |
void swap(stack<T, Container>& x, stack<T, Container>& y) noexcept(noexcept(x.swap(y)));
|
| 672 |
```
|
| 673 |
|
| 674 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 675 |
+
unless `is_swappable_v<Container>` is `true`.
|
| 676 |
+
|
| 677 |
+
*Effects:* As if by `x.swap(y)`.
|
| 678 |
|
| 679 |
<!-- Link reference definitions -->
|
| 680 |
[alg.sorting]: algorithms.md#alg.sorting
|
| 681 |
[algorithm.stable]: library.md#algorithm.stable
|
| 682 |
[algorithms]: algorithms.md#algorithms
|
| 683 |
[allocator.requirements]: library.md#allocator.requirements
|
| 684 |
+
[allocator.requirements.completeness]: library.md#allocator.requirements.completeness
|
| 685 |
[allocator.traits.members]: utilities.md#allocator.traits.members
|
| 686 |
[array]: #array
|
| 687 |
[array.cons]: #array.cons
|
| 688 |
[array.data]: #array.data
|
| 689 |
[array.fill]: #array.fill
|
| 690 |
[array.overview]: #array.overview
|
| 691 |
[array.size]: #array.size
|
| 692 |
[array.special]: #array.special
|
| 693 |
[array.swap]: #array.swap
|
| 694 |
+
[array.syn]: #array.syn
|
| 695 |
[array.tuple]: #array.tuple
|
| 696 |
[array.zero]: #array.zero
|
| 697 |
[associative]: #associative
|
| 698 |
[associative.general]: #associative.general
|
| 699 |
[associative.map.syn]: #associative.map.syn
|
|
|
|
| 704 |
[class.copy]: special.md#class.copy
|
| 705 |
[class.ctor]: special.md#class.ctor
|
| 706 |
[class.dtor]: special.md#class.dtor
|
| 707 |
[container.adaptors]: #container.adaptors
|
| 708 |
[container.adaptors.general]: #container.adaptors.general
|
| 709 |
+
[container.insert.return]: #container.insert.return
|
| 710 |
+
[container.node]: #container.node
|
| 711 |
+
[container.node.cons]: #container.node.cons
|
| 712 |
+
[container.node.dtor]: #container.node.dtor
|
| 713 |
+
[container.node.modifiers]: #container.node.modifiers
|
| 714 |
+
[container.node.observers]: #container.node.observers
|
| 715 |
+
[container.node.overview]: #container.node.overview
|
| 716 |
[container.requirements]: #container.requirements
|
| 717 |
[container.requirements.dataraces]: #container.requirements.dataraces
|
| 718 |
[container.requirements.general]: #container.requirements.general
|
| 719 |
[containers]: #containers
|
| 720 |
[containers.general]: #containers.general
|
|
|
|
| 723 |
[deque.capacity]: #deque.capacity
|
| 724 |
[deque.cons]: #deque.cons
|
| 725 |
[deque.modifiers]: #deque.modifiers
|
| 726 |
[deque.overview]: #deque.overview
|
| 727 |
[deque.special]: #deque.special
|
| 728 |
+
[deque.syn]: #deque.syn
|
| 729 |
[forward.iterators]: iterators.md#forward.iterators
|
| 730 |
+
[forward_list.syn]: #forward_list.syn
|
| 731 |
[forwardlist]: #forwardlist
|
| 732 |
[forwardlist.access]: #forwardlist.access
|
| 733 |
[forwardlist.cons]: #forwardlist.cons
|
| 734 |
[forwardlist.iter]: #forwardlist.iter
|
| 735 |
[forwardlist.modifiers]: #forwardlist.modifiers
|
| 736 |
[forwardlist.ops]: #forwardlist.ops
|
| 737 |
[forwardlist.overview]: #forwardlist.overview
|
| 738 |
[forwardlist.spec]: #forwardlist.spec
|
| 739 |
[hash.requirements]: library.md#hash.requirements
|
| 740 |
[iterator.requirements]: iterators.md#iterator.requirements
|
| 741 |
+
[iterator.requirements.general]: iterators.md#iterator.requirements.general
|
| 742 |
[list]: #list
|
| 743 |
[list.capacity]: #list.capacity
|
| 744 |
[list.cons]: #list.cons
|
| 745 |
[list.modifiers]: #list.modifiers
|
| 746 |
[list.ops]: #list.ops
|
| 747 |
[list.overview]: #list.overview
|
| 748 |
[list.special]: #list.special
|
| 749 |
+
[list.syn]: #list.syn
|
| 750 |
[map]: #map
|
| 751 |
[map.access]: #map.access
|
| 752 |
[map.cons]: #map.cons
|
| 753 |
[map.modifiers]: #map.modifiers
|
| 754 |
[map.overview]: #map.overview
|
|
|
|
| 772 |
[queue.cons.alloc]: #queue.cons.alloc
|
| 773 |
[queue.defn]: #queue.defn
|
| 774 |
[queue.ops]: #queue.ops
|
| 775 |
[queue.special]: #queue.special
|
| 776 |
[queue.syn]: #queue.syn
|
| 777 |
+
[random.access.iterators]: iterators.md#random.access.iterators
|
| 778 |
[res.on.data.races]: library.md#res.on.data.races
|
| 779 |
[sequence.reqmts]: #sequence.reqmts
|
| 780 |
[sequences]: #sequences
|
| 781 |
[sequences.general]: #sequences.general
|
| 782 |
[set]: #set
|
|
|
|
| 789 |
[stack.defn]: #stack.defn
|
| 790 |
[stack.ops]: #stack.ops
|
| 791 |
[stack.special]: #stack.special
|
| 792 |
[stack.syn]: #stack.syn
|
| 793 |
[strings]: strings.md#strings
|
| 794 |
+
[swappable.requirements]: library.md#swappable.requirements
|
| 795 |
[tab:HashRequirements]: #tab:HashRequirements
|
| 796 |
[tab:containers.allocatoraware]: #tab:containers.allocatoraware
|
| 797 |
[tab:containers.associative.requirements]: #tab:containers.associative.requirements
|
| 798 |
[tab:containers.container.requirements]: #tab:containers.container.requirements
|
| 799 |
[tab:containers.lib.summary]: #tab:containers.lib.summary
|
| 800 |
+
[tab:containers.node.compat]: #tab:containers.node.compat
|
| 801 |
[tab:containers.optional.operations]: #tab:containers.optional.operations
|
| 802 |
[tab:containers.reversible.requirements]: #tab:containers.reversible.requirements
|
| 803 |
[tab:containers.sequence.optional]: #tab:containers.sequence.optional
|
| 804 |
[tab:containers.sequence.requirements]: #tab:containers.sequence.requirements
|
| 805 |
[temp.deduct]: temp.md#temp.deduct
|
|
|
|
| 835 |
[vector.cons]: #vector.cons
|
| 836 |
[vector.data]: #vector.data
|
| 837 |
[vector.modifiers]: #vector.modifiers
|
| 838 |
[vector.overview]: #vector.overview
|
| 839 |
[vector.special]: #vector.special
|
| 840 |
+
[vector.syn]: #vector.syn
|
| 841 |
|
| 842 |
[^1]: Equality comparison is a refinement of partitioning if no two
|
| 843 |
objects that compare equal fall into different partitions.
|
| 844 |
|
| 845 |
[^2]: These member functions are only provided by containers whose
|