- tmp/tmp7t8cthle/{from.md → to.md} +346 -278
tmp/tmp7t8cthle/{from.md → to.md}
RENAMED
|
@@ -4,11 +4,10 @@
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
#include <initializer_list>
|
| 7 |
|
| 8 |
namespace std {
|
| 9 |
-
|
| 10 |
template<class T> class valarray; // An array of type T
|
| 11 |
class slice; // a BLAS-like slice out of an array
|
| 12 |
template<class T> class slice_array;
|
| 13 |
class gslice; // a generalized slice out of an array
|
| 14 |
template<class T> class gslice_array;
|
|
@@ -147,11 +146,11 @@ additional functions and operators as follows:
|
|
| 147 |
identical functions taking every combination of `const valarray<T>&`
|
| 148 |
and replacement types shall be added.
|
| 149 |
|
| 150 |
In particular, an implementation shall allow a `valarray<T>` to be
|
| 151 |
constructed from such replacement types and shall allow assignments and
|
| 152 |
-
|
| 153 |
`gslice_array<T>`, `mask_array<T>` and `indirect_array<T>` objects.
|
| 154 |
|
| 155 |
These library functions are permitted to throw a `bad_alloc` (
|
| 156 |
[[bad.alloc]]) exception if there are not sufficient resources available
|
| 157 |
to carry out the operation. Note that the exception is not mandated.
|
|
@@ -162,13 +161,13 @@ to carry out the operation. Note that the exception is not mandated.
|
|
| 162 |
|
| 163 |
``` cpp
|
| 164 |
namespace std {
|
| 165 |
template<class T> class valarray {
|
| 166 |
public:
|
| 167 |
-
|
| 168 |
|
| 169 |
-
// [valarray.cons] construct/destroy
|
| 170 |
valarray();
|
| 171 |
explicit valarray(size_t);
|
| 172 |
valarray(const T&, size_t);
|
| 173 |
valarray(const T*, size_t);
|
| 174 |
valarray(const valarray&);
|
|
@@ -178,149 +177,151 @@ namespace std {
|
|
| 178 |
valarray(const mask_array<T>&);
|
| 179 |
valarray(const indirect_array<T>&);
|
| 180 |
valarray(initializer_list<T>);
|
| 181 |
~valarray();
|
| 182 |
|
| 183 |
-
// [valarray.assign] assignment
|
| 184 |
-
valarray
|
| 185 |
-
valarray
|
| 186 |
valarray& operator=(initializer_list<T>);
|
| 187 |
-
valarray
|
| 188 |
-
valarray
|
| 189 |
-
valarray
|
| 190 |
-
valarray
|
| 191 |
-
valarray
|
| 192 |
|
| 193 |
-
// [valarray.access] element access
|
| 194 |
const T& operator[](size_t) const;
|
| 195 |
T& operator[](size_t);
|
| 196 |
|
| 197 |
-
// [valarray.sub] subset operations
|
| 198 |
-
valarray
|
| 199 |
slice_array<T> operator[](slice);
|
| 200 |
-
valarray
|
| 201 |
gslice_array<T> operator[](const gslice&);
|
| 202 |
-
valarray
|
| 203 |
mask_array<T> operator[](const valarray<bool>&);
|
| 204 |
-
valarray
|
| 205 |
indirect_array<T> operator[](const valarray<size_t>&);
|
| 206 |
|
| 207 |
-
// [valarray.unary] unary operators
|
| 208 |
-
valarray
|
| 209 |
-
valarray
|
| 210 |
-
valarray
|
| 211 |
valarray<bool> operator!() const;
|
| 212 |
|
| 213 |
-
// [valarray.cassign]
|
| 214 |
-
valarray
|
| 215 |
-
valarray
|
| 216 |
-
valarray
|
| 217 |
-
valarray
|
| 218 |
-
valarray
|
| 219 |
-
valarray
|
| 220 |
-
valarray
|
| 221 |
-
valarray
|
| 222 |
-
valarray
|
| 223 |
-
valarray
|
| 224 |
|
| 225 |
-
valarray
|
| 226 |
-
valarray
|
| 227 |
-
valarray
|
| 228 |
-
valarray
|
| 229 |
-
valarray
|
| 230 |
-
valarray
|
| 231 |
-
valarray
|
| 232 |
-
valarray
|
| 233 |
-
valarray
|
| 234 |
-
valarray
|
| 235 |
|
| 236 |
-
// [valarray.members] member functions
|
| 237 |
void swap(valarray&) noexcept;
|
| 238 |
|
| 239 |
size_t size() const;
|
| 240 |
|
| 241 |
T sum() const;
|
| 242 |
T min() const;
|
| 243 |
T max() const;
|
| 244 |
|
| 245 |
-
valarray
|
| 246 |
-
valarray
|
| 247 |
-
valarray
|
| 248 |
-
valarray
|
| 249 |
void resize(size_t sz, T c = T());
|
| 250 |
};
|
|
|
|
|
|
|
| 251 |
}
|
| 252 |
```
|
| 253 |
|
| 254 |
The class template `valarray<T>` is a one-dimensional smart array, with
|
| 255 |
elements numbered sequentially from zero. It is a representation of the
|
| 256 |
-
mathematical concept of an ordered set of values.
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
the
|
|
|
|
|
|
|
| 260 |
|
| 261 |
An implementation is permitted to qualify any of the functions declared
|
| 262 |
in `<valarray>` as `inline`.
|
| 263 |
|
| 264 |
#### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
|
| 265 |
|
| 266 |
``` cpp
|
| 267 |
valarray();
|
| 268 |
```
|
| 269 |
|
| 270 |
-
*Effects:* Constructs
|
| 271 |
-
zero length.[^10]
|
| 272 |
|
| 273 |
``` cpp
|
| 274 |
-
explicit valarray(size_t);
|
| 275 |
```
|
| 276 |
|
| 277 |
-
|
| 278 |
-
the
|
| 279 |
-
value-initialized ([[dcl.init]]).
|
| 280 |
|
| 281 |
``` cpp
|
| 282 |
-
valarray(const T&, size_t);
|
| 283 |
```
|
| 284 |
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
the first argument.
|
| 288 |
|
| 289 |
``` cpp
|
| 290 |
-
valarray(const T*, size_t);
|
| 291 |
```
|
| 292 |
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
|
|
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
-
valarray(const valarray
|
| 301 |
```
|
| 302 |
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
-
valarray(valarray
|
| 309 |
```
|
| 310 |
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
|
| 315 |
*Complexity:* Constant.
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
valarray(initializer_list<T> il);
|
| 319 |
```
|
| 320 |
|
| 321 |
-
*Effects:*
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
valarray(const slice_array<T>&);
|
| 325 |
valarray(const gslice_array<T>&);
|
| 326 |
valarray(const mask_array<T>&);
|
|
@@ -332,101 +333,103 @@ templates to a `valarray`.
|
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
~valarray();
|
| 335 |
```
|
| 336 |
|
| 337 |
-
The destructor is applied to every element of `*this`; an
|
| 338 |
-
may return all allocated memory.
|
| 339 |
|
| 340 |
#### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
|
| 341 |
|
| 342 |
``` cpp
|
| 343 |
-
valarray
|
| 344 |
```
|
| 345 |
|
| 346 |
-
Each element of the `*this` array is assigned the value of
|
| 347 |
-
corresponding element of
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
|
| 352 |
-
`size() == v.size()`.
|
|
|
|
|
|
|
| 353 |
|
| 354 |
``` cpp
|
| 355 |
-
valarray
|
| 356 |
```
|
| 357 |
|
| 358 |
*Effects:* `*this` obtains the value of `v`. The value of `v` after the
|
| 359 |
assignment is not specified.
|
| 360 |
|
|
|
|
|
|
|
| 361 |
*Complexity:* Linear.
|
| 362 |
|
| 363 |
``` cpp
|
| 364 |
valarray& operator=(initializer_list<T> il);
|
| 365 |
```
|
| 366 |
|
| 367 |
-
*Effects:* `*this = valarray(il)`
|
| 368 |
-
|
| 369 |
-
*Returns:* `*this`.
|
| 370 |
|
| 371 |
``` cpp
|
| 372 |
-
valarray
|
| 373 |
```
|
| 374 |
|
| 375 |
-
|
| 376 |
-
|
|
|
|
| 377 |
|
| 378 |
``` cpp
|
| 379 |
-
valarray
|
| 380 |
-
valarray
|
| 381 |
-
valarray
|
| 382 |
-
valarray
|
| 383 |
```
|
| 384 |
|
| 385 |
*Requires:* The length of the array to which the argument refers equals
|
| 386 |
-
`size()`.
|
|
|
|
|
|
|
| 387 |
|
| 388 |
These operators allow the results of a generalized subscripting
|
| 389 |
operation to be assigned directly to a `valarray`.
|
| 390 |
|
| 391 |
-
If the value of an element in the left-hand side of a valarray
|
| 392 |
-
assignment operator depends on the value of another element in that
|
| 393 |
-
left-hand side, the resulting behavior is undefined.
|
| 394 |
-
|
| 395 |
#### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
|
| 396 |
|
| 397 |
``` cpp
|
| 398 |
-
const T& operator[](size_t) const;
|
| 399 |
-
T& operator[](size_t);
|
| 400 |
```
|
| 401 |
|
| 402 |
-
|
| 403 |
-
of the array.
|
| 404 |
|
| 405 |
-
|
| 406 |
-
non-constant `valarray<T> a`, any `T q`, and for any `size_t i` such
|
| 407 |
-
that the value of `i` is less than the length of `a`.
|
| 408 |
|
| 409 |
-
The expression `
|
| 410 |
-
|
| 411 |
-
|
|
|
|
| 412 |
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 418 |
|
| 419 |
The reference returned by the subscript operator for an array shall be
|
| 420 |
valid until the member function
|
| 421 |
`resize(size_t, T)` ([[valarray.members]]) is called for that array or
|
| 422 |
until the lifetime of that array ends, whichever happens first.
|
| 423 |
|
| 424 |
-
If the subscript operator is invoked with a `size_t` argument whose
|
| 425 |
-
value is not less than the length of the array, the behavior is
|
| 426 |
-
undefined.
|
| 427 |
-
|
| 428 |
#### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
|
| 429 |
|
| 430 |
The member `operator[]` is overloaded to provide several ways to select
|
| 431 |
sequences of elements from among those controlled by `*this`. Each of
|
| 432 |
these operations returns a subset of the array. The const-qualified
|
|
@@ -436,200 +439,231 @@ the original array, working in conjunction with various overloads of
|
|
| 436 |
`operator=` and other assigning operators to allow selective replacement
|
| 437 |
(slicing) of the controlled sequence. In each case the selected
|
| 438 |
element(s) must exist.
|
| 439 |
|
| 440 |
``` cpp
|
| 441 |
-
valarray
|
| 442 |
```
|
| 443 |
|
| 444 |
-
*Returns:*
|
| 445 |
-
|
|
|
|
|
|
|
| 446 |
|
| 447 |
``` cpp
|
| 448 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 449 |
// v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
|
| 450 |
```
|
| 451 |
|
|
|
|
|
|
|
| 452 |
``` cpp
|
| 453 |
slice_array<T> operator[](slice slicearr);
|
| 454 |
```
|
| 455 |
|
| 456 |
*Returns:* An object that holds references to elements of the controlled
|
| 457 |
sequence selected by `slicearr`.
|
| 458 |
|
|
|
|
|
|
|
| 459 |
``` cpp
|
| 460 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 461 |
valarray<char> v1("ABCDE", 5);
|
| 462 |
v0[slice(2, 5, 3)] = v1;
|
| 463 |
// v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
|
| 464 |
```
|
| 465 |
|
|
|
|
|
|
|
| 466 |
``` cpp
|
| 467 |
-
valarray
|
| 468 |
```
|
| 469 |
|
| 470 |
-
*Returns:*
|
| 471 |
-
|
|
|
|
|
|
|
| 472 |
|
| 473 |
``` cpp
|
| 474 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 475 |
const size_t lv[] = { 2, 3 };
|
| 476 |
const size_t dv[] = { 7, 2 };
|
| 477 |
const valarray<size_t> len(lv, 2), str(dv, 2);
|
| 478 |
// v0[gslice(3, len, str)] returns
|
| 479 |
// valarray<char>("dfhkmo", 6)
|
| 480 |
```
|
| 481 |
|
|
|
|
|
|
|
| 482 |
``` cpp
|
| 483 |
gslice_array<T> operator[](const gslice& gslicearr);
|
| 484 |
```
|
| 485 |
|
| 486 |
*Returns:* An object that holds references to elements of the controlled
|
| 487 |
sequence selected by `gslicearr`.
|
| 488 |
|
|
|
|
|
|
|
| 489 |
``` cpp
|
| 490 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 491 |
-
valarray<char> v1("
|
| 492 |
const size_t lv[] = { 2, 3 };
|
| 493 |
const size_t dv[] = { 7, 2 };
|
| 494 |
const valarray<size_t> len(lv, 2), str(dv, 2);
|
| 495 |
v0[gslice(3, len, str)] = v1;
|
| 496 |
// v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
|
| 497 |
```
|
| 498 |
|
|
|
|
|
|
|
| 499 |
``` cpp
|
| 500 |
-
valarray
|
| 501 |
```
|
| 502 |
|
| 503 |
-
*Returns:*
|
| 504 |
-
|
|
|
|
|
|
|
| 505 |
|
| 506 |
``` cpp
|
| 507 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 508 |
const bool vb[] = { false, false, true, true, false, true };
|
| 509 |
// v0[valarray<bool>(vb, 6)] returns
|
| 510 |
// valarray<char>("cdf", 3)
|
| 511 |
```
|
| 512 |
|
|
|
|
|
|
|
| 513 |
``` cpp
|
| 514 |
mask_array<T> operator[](const valarray<bool>& boolarr);
|
| 515 |
```
|
| 516 |
|
| 517 |
*Returns:* An object that holds references to elements of the controlled
|
| 518 |
sequence selected by `boolarr`.
|
| 519 |
|
|
|
|
|
|
|
| 520 |
``` cpp
|
| 521 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 522 |
valarray<char> v1("ABC", 3);
|
| 523 |
const bool vb[] = { false, false, true, true, false, true };
|
| 524 |
v0[valarray<bool>(vb, 6)] = v1;
|
| 525 |
// v0 == valarray<char>("abABeCghijklmnop", 16)
|
| 526 |
```
|
| 527 |
|
|
|
|
|
|
|
| 528 |
``` cpp
|
| 529 |
-
valarray
|
| 530 |
```
|
| 531 |
|
| 532 |
-
*Returns:*
|
| 533 |
-
|
|
|
|
|
|
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 537 |
const size_t vi[] = { 7, 5, 2, 3, 8 };
|
| 538 |
// v0[valarray<size_t>(vi, 5)] returns
|
| 539 |
// valarray<char>("hfcdi", 5)
|
| 540 |
```
|
| 541 |
|
|
|
|
|
|
|
| 542 |
``` cpp
|
| 543 |
indirect_array<T> operator[](const valarray<size_t>& indarr);
|
| 544 |
```
|
| 545 |
|
| 546 |
*Returns:* An object that holds references to elements of the controlled
|
| 547 |
sequence selected by `indarr`.
|
| 548 |
|
|
|
|
|
|
|
| 549 |
``` cpp
|
| 550 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 551 |
valarray<char> v1("ABCDE", 5);
|
| 552 |
const size_t vi[] = { 7, 5, 2, 3, 8 };
|
| 553 |
v0[valarray<size_t>(vi, 5)] = v1;
|
| 554 |
// v0 == valarray<char>("abCDeBgAEjklmnop", 16)
|
| 555 |
```
|
| 556 |
|
|
|
|
|
|
|
| 557 |
#### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
|
| 558 |
|
| 559 |
``` cpp
|
| 560 |
-
valarray
|
| 561 |
-
valarray
|
| 562 |
-
valarray
|
| 563 |
valarray<bool> operator!() const;
|
| 564 |
```
|
| 565 |
|
| 566 |
-
Each of these operators may only be instantiated for a type
|
| 567 |
-
the indicated operator can be applied and for which the
|
| 568 |
-
operator returns a value which is of type `T` (`bool` for
|
| 569 |
-
or which may be unambiguously implicitly converted to type
|
| 570 |
-
for `operator!`).
|
| 571 |
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
element of the array.
|
| 576 |
|
| 577 |
-
#### `valarray`
|
| 578 |
|
| 579 |
``` cpp
|
| 580 |
-
valarray
|
| 581 |
-
valarray
|
| 582 |
-
valarray
|
| 583 |
-
valarray
|
| 584 |
-
valarray
|
| 585 |
-
valarray
|
| 586 |
-
valarray
|
| 587 |
-
valarray
|
| 588 |
-
valarray
|
| 589 |
-
valarray
|
| 590 |
```
|
| 591 |
|
| 592 |
-
Each of these operators may only be
|
| 593 |
-
the indicated operator can be applied
|
| 594 |
-
|
| 595 |
-
|
|
|
|
| 596 |
|
| 597 |
-
|
|
|
|
| 598 |
|
| 599 |
-
|
| 600 |
-
behavior is undefined. The appearance of an array on the left-hand side
|
| 601 |
-
of a computed assignment does `not` invalidate references or pointers.
|
| 602 |
|
| 603 |
-
|
| 604 |
-
assignment
|
| 605 |
-
hand side, the resulting behavior is undefined.
|
| 606 |
|
| 607 |
``` cpp
|
| 608 |
-
valarray
|
| 609 |
-
valarray
|
| 610 |
-
valarray
|
| 611 |
-
valarray
|
| 612 |
-
valarray
|
| 613 |
-
valarray
|
| 614 |
-
valarray
|
| 615 |
-
valarray
|
| 616 |
-
valarray
|
| 617 |
-
valarray
|
| 618 |
```
|
| 619 |
|
| 620 |
-
Each of these operators may only be instantiated for a type
|
| 621 |
-
the indicated operator can be applied
|
|
|
|
| 622 |
|
| 623 |
-
Each of these operators applies the indicated operation to
|
| 624 |
-
|
| 625 |
|
| 626 |
-
|
| 627 |
|
| 628 |
-
The appearance of an array on the left-hand side of a
|
| 629 |
-
assignment does
|
| 630 |
-
of the array.
|
| 631 |
|
| 632 |
#### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
|
| 633 |
|
| 634 |
``` cpp
|
| 635 |
void swap(valarray& v) noexcept;
|
|
@@ -650,55 +684,81 @@ size_t size() const;
|
|
| 650 |
|
| 651 |
``` cpp
|
| 652 |
T sum() const;
|
| 653 |
```
|
| 654 |
|
| 655 |
-
This function may only be instantiated for a
|
| 656 |
-
`operator+=` can be applied.
|
| 657 |
-
elements of the array.
|
| 658 |
|
| 659 |
-
|
| 660 |
-
length 1,
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
unspecified order.
|
| 664 |
|
| 665 |
``` cpp
|
| 666 |
T min() const;
|
| 667 |
```
|
| 668 |
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
|
|
|
| 673 |
|
| 674 |
``` cpp
|
| 675 |
T max() const;
|
| 676 |
```
|
| 677 |
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
|
| 681 |
-
|
|
|
|
| 682 |
|
| 683 |
``` cpp
|
| 684 |
-
valarray
|
| 685 |
```
|
| 686 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 687 |
``` cpp
|
| 688 |
-
valarray
|
| 689 |
```
|
| 690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 691 |
``` cpp
|
| 692 |
-
valarray
|
| 693 |
-
valarray
|
| 694 |
```
|
| 695 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
``` cpp
|
| 697 |
void resize(size_t sz, T c = T());
|
| 698 |
```
|
| 699 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 700 |
### `valarray` non-member operations <a id="valarray.nonmembers">[[valarray.nonmembers]]</a>
|
| 701 |
|
| 702 |
#### `valarray` binary operators <a id="valarray.binary">[[valarray.binary]]</a>
|
| 703 |
|
| 704 |
``` cpp
|
|
@@ -722,22 +782,20 @@ template<class T> valarray<T> operator<<
|
|
| 722 |
(const valarray<T>&, const valarray<T>&);
|
| 723 |
template<class T> valarray<T> operator>>
|
| 724 |
(const valarray<T>&, const valarray<T>&);
|
| 725 |
```
|
| 726 |
|
| 727 |
-
Each of these operators may only be instantiated for a type
|
| 728 |
-
the indicated operator can be applied and for which the
|
| 729 |
-
operator returns a value which is of type `T` or which can be
|
| 730 |
-
unambiguously implicitly converted to type `T`.
|
|
|
|
| 731 |
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
If the argument arrays do not have the same length, the behavior is
|
| 738 |
-
undefined.
|
| 739 |
|
| 740 |
``` cpp
|
| 741 |
template<class T> valarray<T> operator* (const valarray<T>&, const T&);
|
| 742 |
template<class T> valarray<T> operator* (const T&, const valarray<T>&);
|
| 743 |
template<class T> valarray<T> operator/ (const valarray<T>&, const T&);
|
|
@@ -758,19 +816,19 @@ template<class T> valarray<T> operator<<(const valarray<T>&, const T&);
|
|
| 758 |
template<class T> valarray<T> operator<<(const T&, const valarray<T>&);
|
| 759 |
template<class T> valarray<T> operator>>(const valarray<T>&, const T&);
|
| 760 |
template<class T> valarray<T> operator>>(const T&, const valarray<T>&);
|
| 761 |
```
|
| 762 |
|
| 763 |
-
Each of these operators may only be instantiated for a type
|
| 764 |
-
the indicated operator can be applied and for which the
|
| 765 |
-
operator returns a value which is of type `T` or which can be
|
| 766 |
unambiguously implicitly converted to type `T`.
|
| 767 |
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
|
| 773 |
#### `valarray` logical operators <a id="valarray.comparison">[[valarray.comparison]]</a>
|
| 774 |
|
| 775 |
``` cpp
|
| 776 |
template<class T> valarray<bool> operator==
|
|
@@ -789,22 +847,20 @@ template<class T> valarray<bool> operator&&
|
|
| 789 |
(const valarray<T>&, const valarray<T>&);
|
| 790 |
template<class T> valarray<bool> operator||
|
| 791 |
(const valarray<T>&, const valarray<T>&);
|
| 792 |
```
|
| 793 |
|
| 794 |
-
Each of these operators may only be instantiated for a type
|
| 795 |
-
the indicated operator can be applied and for which the
|
| 796 |
-
operator returns a value which is of type `bool` or which can
|
| 797 |
-
unambiguously implicitly converted to type `bool`.
|
|
|
|
| 798 |
|
| 799 |
-
|
| 800 |
-
|
| 801 |
-
|
| 802 |
-
|
| 803 |
-
|
| 804 |
-
If the two array arguments do not have the same length, the behavior is
|
| 805 |
-
undefined.
|
| 806 |
|
| 807 |
``` cpp
|
| 808 |
template<class T> valarray<bool> operator==(const valarray<T>&, const T&);
|
| 809 |
template<class T> valarray<bool> operator==(const T&, const valarray<T>&);
|
| 810 |
template<class T> valarray<bool> operator!=(const valarray<T>&, const T&);
|
|
@@ -821,19 +877,19 @@ template<class T> valarray<bool> operator&&(const valarray<T>&, const T&);
|
|
| 821 |
template<class T> valarray<bool> operator&&(const T&, const valarray<T>&);
|
| 822 |
template<class T> valarray<bool> operator||(const valarray<T>&, const T&);
|
| 823 |
template<class T> valarray<bool> operator||(const T&, const valarray<T>&);
|
| 824 |
```
|
| 825 |
|
| 826 |
-
Each of these operators may only be instantiated for a type
|
| 827 |
-
the indicated operator can be applied and for which the
|
| 828 |
-
operator returns a value which is of type `bool` or which can
|
| 829 |
-
unambiguously implicitly converted to type `bool`.
|
| 830 |
|
| 831 |
-
|
| 832 |
-
|
| 833 |
-
|
| 834 |
-
|
| 835 |
|
| 836 |
#### `valarray` transcendentals <a id="valarray.transcend">[[valarray.transcend]]</a>
|
| 837 |
|
| 838 |
``` cpp
|
| 839 |
template<class T> valarray<T> abs (const valarray<T>&);
|
|
@@ -858,22 +914,22 @@ template<class T> valarray<T> sinh (const valarray<T>&);
|
|
| 858 |
template<class T> valarray<T> sqrt (const valarray<T>&);
|
| 859 |
template<class T> valarray<T> tan (const valarray<T>&);
|
| 860 |
template<class T> valarray<T> tanh (const valarray<T>&);
|
| 861 |
```
|
| 862 |
|
| 863 |
-
Each of these functions may only be instantiated for a type
|
| 864 |
-
a unique function with the indicated name can be applied
|
| 865 |
-
This function shall return a value which is of type `T`
|
| 866 |
-
unambiguously implicitly converted to type `T`.
|
| 867 |
|
| 868 |
#### `valarray` specialized algorithms <a id="valarray.special">[[valarray.special]]</a>
|
| 869 |
|
| 870 |
``` cpp
|
| 871 |
template <class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
|
| 872 |
```
|
| 873 |
|
| 874 |
-
*Effects:* `x.swap(y)`.
|
| 875 |
|
| 876 |
### Class `slice` <a id="class.slice">[[class.slice]]</a>
|
| 877 |
|
| 878 |
#### Class `slice` overview <a id="class.slice.overview">[[class.slice.overview]]</a>
|
| 879 |
|
|
@@ -890,11 +946,11 @@ namespace std {
|
|
| 890 |
};
|
| 891 |
}
|
| 892 |
```
|
| 893 |
|
| 894 |
The `slice` class represents a BLAS-like slice from an array. Such a
|
| 895 |
-
slice is specified by a starting index, a length, and a stride.[^
|
| 896 |
|
| 897 |
#### `slice` constructors <a id="cons.slice">[[cons.slice]]</a>
|
| 898 |
|
| 899 |
``` cpp
|
| 900 |
slice();
|
|
@@ -905,12 +961,12 @@ slice(const slice&);
|
|
| 905 |
The default constructor is equivalent to `slice(0, 0, 0)`. A default
|
| 906 |
constructor is provided only to permit the declaration of arrays of
|
| 907 |
slices. The constructor with arguments for a slice takes a start,
|
| 908 |
length, and stride parameter.
|
| 909 |
|
| 910 |
-
`slice(3, 8, 2)` constructs a slice which selects
|
| 911 |
-
17 from an array.
|
| 912 |
|
| 913 |
#### `slice` access functions <a id="slice.access">[[slice.access]]</a>
|
| 914 |
|
| 915 |
``` cpp
|
| 916 |
size_t start() const;
|
|
@@ -928,11 +984,11 @@ size_t stride() const;
|
|
| 928 |
|
| 929 |
``` cpp
|
| 930 |
namespace std {
|
| 931 |
template <class T> class slice_array {
|
| 932 |
public:
|
| 933 |
-
|
| 934 |
|
| 935 |
void operator= (const valarray<T>&) const;
|
| 936 |
void operator*= (const valarray<T>&) const;
|
| 937 |
void operator/= (const valarray<T>&) const;
|
| 938 |
void operator%= (const valarray<T>&) const;
|
|
@@ -962,13 +1018,14 @@ slice_array<T> valarray<T>::operator[](slice);
|
|
| 962 |
```
|
| 963 |
|
| 964 |
It has reference semantics to a subset of an array specified by a
|
| 965 |
`slice` object.
|
| 966 |
|
| 967 |
-
The expression `a[slice(1, 5, 3)] = b;` has the effect of
|
| 968 |
-
elements of `b` to a slice of the elements in `a`. For the
|
| 969 |
-
the elements selected from `a` are 1, 4, ...,
|
|
|
|
| 970 |
|
| 971 |
#### `slice_array` assignment <a id="slice.arr.assign">[[slice.arr.assign]]</a>
|
| 972 |
|
| 973 |
``` cpp
|
| 974 |
void operator=(const valarray<T>&) const;
|
|
@@ -977,11 +1034,11 @@ const slice_array& operator=(const slice_array&) const;
|
|
| 977 |
|
| 978 |
These assignment operators have reference semantics, assigning the
|
| 979 |
values of the argument array elements to selected elements of the
|
| 980 |
`valarray<T>` object to which the `slice_array` object refers.
|
| 981 |
|
| 982 |
-
#### `slice_array`
|
| 983 |
|
| 984 |
``` cpp
|
| 985 |
void operator*= (const valarray<T>&) const;
|
| 986 |
void operator/= (const valarray<T>&) const;
|
| 987 |
void operator%= (const valarray<T>&) const;
|
|
@@ -992,11 +1049,11 @@ void operator&= (const valarray<T>&) const;
|
|
| 992 |
void operator|= (const valarray<T>&) const;
|
| 993 |
void operator<<=(const valarray<T>&) const;
|
| 994 |
void operator>>=(const valarray<T>&) const;
|
| 995 |
```
|
| 996 |
|
| 997 |
-
These
|
| 998 |
indicated operation to the elements of the argument array and selected
|
| 999 |
elements of the `valarray<T>` object to which the `slice_array` object
|
| 1000 |
refers.
|
| 1001 |
|
| 1002 |
#### `slice_array` fill function <a id="slice.arr.fill">[[slice.arr.fill]]</a>
|
|
@@ -1036,34 +1093,40 @@ number to the number of strides, to a single index k. It is useful for
|
|
| 1036 |
building multidimensional array classes using the `valarray` template,
|
| 1037 |
which is one-dimensional. The set of one-dimensional index values
|
| 1038 |
specified by a `gslice` are $$k = s + \sum_j i_j d_j$$ where the
|
| 1039 |
multidimensional indices iⱼ range in value from 0 to lᵢⱼ - 1.
|
| 1040 |
|
|
|
|
|
|
|
| 1041 |
The `gslice` specification
|
| 1042 |
|
| 1043 |
``` cpp
|
| 1044 |
start = 3
|
| 1045 |
length = {2, 4, 3}
|
| 1046 |
stride = {19, 4, 1}
|
| 1047 |
```
|
| 1048 |
|
| 1049 |
yields the sequence of one-dimensional indices
|
| 1050 |
-
|
| 1051 |
$$k = 3 + (0, 1) \times 19 + (0, 1, 2, 3) \times 4 + (0, 1, 2) \times 1$$
|
| 1052 |
-
|
| 1053 |
which are ordered as shown in the following table:
|
| 1054 |
|
| 1055 |
That is, the highest-ordered index turns fastest.
|
| 1056 |
|
|
|
|
|
|
|
| 1057 |
It is possible to have degenerate generalized slices in which an address
|
| 1058 |
is repeated.
|
| 1059 |
|
|
|
|
|
|
|
| 1060 |
If the stride parameters in the previous example are changed to {1, 1,
|
| 1061 |
1}, the first few elements of the resulting sequence of indices will be
|
| 1062 |
|
|
|
|
|
|
|
| 1063 |
If a degenerate slice is used as the argument to the non-`const` version
|
| 1064 |
-
of `operator[](const gslice&)`, the
|
| 1065 |
|
| 1066 |
#### `gslice` constructors <a id="gslice.cons">[[gslice.cons]]</a>
|
| 1067 |
|
| 1068 |
``` cpp
|
| 1069 |
gslice();
|
|
@@ -1097,11 +1160,11 @@ linear in the number of strides.
|
|
| 1097 |
|
| 1098 |
``` cpp
|
| 1099 |
namespace std {
|
| 1100 |
template <class T> class gslice_array {
|
| 1101 |
public:
|
| 1102 |
-
|
| 1103 |
|
| 1104 |
void operator= (const valarray<T>&) const;
|
| 1105 |
void operator*= (const valarray<T>&) const;
|
| 1106 |
void operator/= (const valarray<T>&) const;
|
| 1107 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1146,11 +1209,11 @@ const gslice_array& operator=(const gslice_array&) const;
|
|
| 1146 |
|
| 1147 |
These assignment operators have reference semantics, assigning the
|
| 1148 |
values of the argument array elements to selected elements of the
|
| 1149 |
`valarray<T>` object to which the `gslice_array` refers.
|
| 1150 |
|
| 1151 |
-
#### `gslice_array` <a id="gslice.array.comp.assign">[[gslice.array.comp.assign]]</a>
|
| 1152 |
|
| 1153 |
``` cpp
|
| 1154 |
void operator*= (const valarray<T>&) const;
|
| 1155 |
void operator/= (const valarray<T>&) const;
|
| 1156 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1161,11 +1224,11 @@ void operator&= (const valarray<T>&) const;
|
|
| 1161 |
void operator|= (const valarray<T>&) const;
|
| 1162 |
void operator<<=(const valarray<T>&) const;
|
| 1163 |
void operator>>=(const valarray<T>&) const;
|
| 1164 |
```
|
| 1165 |
|
| 1166 |
-
These
|
| 1167 |
indicated operation to the elements of the argument array and selected
|
| 1168 |
elements of the `valarray<T>` object to which the `gslice_array` object
|
| 1169 |
refers.
|
| 1170 |
|
| 1171 |
#### `gslice_array` fill function <a id="gslice.array.fill">[[gslice.array.fill]]</a>
|
|
@@ -1184,11 +1247,11 @@ argument to the elements of the `valarray<T>` object to which the
|
|
| 1184 |
|
| 1185 |
``` cpp
|
| 1186 |
namespace std {
|
| 1187 |
template <class T> class mask_array {
|
| 1188 |
public:
|
| 1189 |
-
|
| 1190 |
|
| 1191 |
void operator= (const valarray<T>&) const;
|
| 1192 |
void operator*= (const valarray<T>&) const;
|
| 1193 |
void operator/= (const valarray<T>&) const;
|
| 1194 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1230,11 +1293,11 @@ const mask_array& operator=(const mask_array&) const;
|
|
| 1230 |
|
| 1231 |
These assignment operators have reference semantics, assigning the
|
| 1232 |
values of the argument array elements to selected elements of the
|
| 1233 |
`valarray<T>` object to which it refers.
|
| 1234 |
|
| 1235 |
-
#### `mask_array`
|
| 1236 |
|
| 1237 |
``` cpp
|
| 1238 |
void operator*= (const valarray<T>&) const;
|
| 1239 |
void operator/= (const valarray<T>&) const;
|
| 1240 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1245,11 +1308,11 @@ void operator&= (const valarray<T>&) const;
|
|
| 1245 |
void operator|= (const valarray<T>&) const;
|
| 1246 |
void operator<<=(const valarray<T>&) const;
|
| 1247 |
void operator>>=(const valarray<T>&) const;
|
| 1248 |
```
|
| 1249 |
|
| 1250 |
-
These
|
| 1251 |
indicated operation to the elements of the argument array and selected
|
| 1252 |
elements of the `valarray<T>` object to which the mask object refers.
|
| 1253 |
|
| 1254 |
#### `mask_array` fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
|
| 1255 |
|
|
@@ -1267,11 +1330,11 @@ argument to the elements of the `valarray<T>` object to which the
|
|
| 1267 |
|
| 1268 |
``` cpp
|
| 1269 |
namespace std {
|
| 1270 |
template <class T> class indirect_array {
|
| 1271 |
public:
|
| 1272 |
-
|
| 1273 |
|
| 1274 |
void operator= (const valarray<T>&) const;
|
| 1275 |
void operator*= (const valarray<T>&) const;
|
| 1276 |
void operator/= (const valarray<T>&) const;
|
| 1277 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1317,21 +1380,25 @@ values of the argument array elements to selected elements of the
|
|
| 1317 |
`valarray<T>` object to which it refers.
|
| 1318 |
|
| 1319 |
If the `indirect_array` specifies an element in the `valarray<T>` object
|
| 1320 |
to which it refers more than once, the behavior is undefined.
|
| 1321 |
|
|
|
|
|
|
|
| 1322 |
``` cpp
|
| 1323 |
int addr[] = {2, 3, 1, 4, 4};
|
| 1324 |
valarray<size_t> indirect(addr, 5);
|
| 1325 |
valarray<double> a(0., 10), b(1., 5);
|
| 1326 |
a[indirect] = b;
|
| 1327 |
```
|
| 1328 |
|
| 1329 |
results in undefined behavior since element 4 is specified twice in the
|
| 1330 |
indirection.
|
| 1331 |
|
| 1332 |
-
|
|
|
|
|
|
|
| 1333 |
|
| 1334 |
``` cpp
|
| 1335 |
void operator*= (const valarray<T>&) const;
|
| 1336 |
void operator/= (const valarray<T>&) const;
|
| 1337 |
void operator%= (const valarray<T>&) const;
|
|
@@ -1342,11 +1409,11 @@ void operator&= (const valarray<T>&) const;
|
|
| 1342 |
void operator|= (const valarray<T>&) const;
|
| 1343 |
void operator<<=(const valarray<T>&) const;
|
| 1344 |
void operator>>=(const valarray<T>&) const;
|
| 1345 |
```
|
| 1346 |
|
| 1347 |
-
These
|
| 1348 |
indicated operation to the elements of the argument array and selected
|
| 1349 |
elements of the `valarray<T>` object to which the `indirect_array`
|
| 1350 |
object refers.
|
| 1351 |
|
| 1352 |
If the `indirect_array` specifies an element in the `valarray<T>` object
|
|
@@ -1360,19 +1427,21 @@ void operator=(const T&) const;
|
|
| 1360 |
|
| 1361 |
This function has reference semantics, assigning the value of its
|
| 1362 |
argument to the elements of the `valarray<T>` object to which the
|
| 1363 |
`indirect_array` object refers.
|
| 1364 |
|
| 1365 |
-
### valarray range access <a id="valarray.range">[[valarray.range]]</a>
|
| 1366 |
|
| 1367 |
In the `begin` and `end` function templates that follow, *unspecified*1
|
| 1368 |
is a type that meets the requirements of a mutable random access
|
| 1369 |
-
iterator ([[random.access.iterators]])
|
| 1370 |
-
|
| 1371 |
-
|
| 1372 |
-
random access iterator (
|
| 1373 |
-
|
|
|
|
|
|
|
| 1374 |
|
| 1375 |
The iterators returned by `begin` and `end` for an array are guaranteed
|
| 1376 |
to be valid until the member function `resize(size_t, T)` (
|
| 1377 |
[[valarray.members]]) is called for that array or until the lifetime of
|
| 1378 |
that array ends, whichever happens first.
|
|
@@ -1380,15 +1449,14 @@ that array ends, whichever happens first.
|
|
| 1380 |
``` cpp
|
| 1381 |
template <class T> unspecified{1} begin(valarray<T>& v);
|
| 1382 |
template <class T> unspecified{2} begin(const valarray<T>& v);
|
| 1383 |
```
|
| 1384 |
|
| 1385 |
-
*Returns:* An iterator referencing the first value in the
|
| 1386 |
|
| 1387 |
``` cpp
|
| 1388 |
template <class T> unspecified{1} end(valarray<T>& v);
|
| 1389 |
template <class T> unspecified{2} end(const valarray<T>& v);
|
| 1390 |
```
|
| 1391 |
|
| 1392 |
-
*Returns:* An iterator referencing one past the last value in the
|
| 1393 |
-
numeric array.
|
| 1394 |
|
|
|
|
| 4 |
|
| 5 |
``` cpp
|
| 6 |
#include <initializer_list>
|
| 7 |
|
| 8 |
namespace std {
|
|
|
|
| 9 |
template<class T> class valarray; // An array of type T
|
| 10 |
class slice; // a BLAS-like slice out of an array
|
| 11 |
template<class T> class slice_array;
|
| 12 |
class gslice; // a generalized slice out of an array
|
| 13 |
template<class T> class gslice_array;
|
|
|
|
| 146 |
identical functions taking every combination of `const valarray<T>&`
|
| 147 |
and replacement types shall be added.
|
| 148 |
|
| 149 |
In particular, an implementation shall allow a `valarray<T>` to be
|
| 150 |
constructed from such replacement types and shall allow assignments and
|
| 151 |
+
compound assignments of such types to `valarray<T>`, `slice_array<T>`,
|
| 152 |
`gslice_array<T>`, `mask_array<T>` and `indirect_array<T>` objects.
|
| 153 |
|
| 154 |
These library functions are permitted to throw a `bad_alloc` (
|
| 155 |
[[bad.alloc]]) exception if there are not sufficient resources available
|
| 156 |
to carry out the operation. Note that the exception is not mandated.
|
|
|
|
| 161 |
|
| 162 |
``` cpp
|
| 163 |
namespace std {
|
| 164 |
template<class T> class valarray {
|
| 165 |
public:
|
| 166 |
+
using value_type = T;
|
| 167 |
|
| 168 |
+
// [valarray.cons], construct/destroy
|
| 169 |
valarray();
|
| 170 |
explicit valarray(size_t);
|
| 171 |
valarray(const T&, size_t);
|
| 172 |
valarray(const T*, size_t);
|
| 173 |
valarray(const valarray&);
|
|
|
|
| 177 |
valarray(const mask_array<T>&);
|
| 178 |
valarray(const indirect_array<T>&);
|
| 179 |
valarray(initializer_list<T>);
|
| 180 |
~valarray();
|
| 181 |
|
| 182 |
+
// [valarray.assign], assignment
|
| 183 |
+
valarray& operator=(const valarray&);
|
| 184 |
+
valarray& operator=(valarray&&) noexcept;
|
| 185 |
valarray& operator=(initializer_list<T>);
|
| 186 |
+
valarray& operator=(const T&);
|
| 187 |
+
valarray& operator=(const slice_array<T>&);
|
| 188 |
+
valarray& operator=(const gslice_array<T>&);
|
| 189 |
+
valarray& operator=(const mask_array<T>&);
|
| 190 |
+
valarray& operator=(const indirect_array<T>&);
|
| 191 |
|
| 192 |
+
// [valarray.access], element access
|
| 193 |
const T& operator[](size_t) const;
|
| 194 |
T& operator[](size_t);
|
| 195 |
|
| 196 |
+
// [valarray.sub], subset operations
|
| 197 |
+
valarray operator[](slice) const;
|
| 198 |
slice_array<T> operator[](slice);
|
| 199 |
+
valarray operator[](const gslice&) const;
|
| 200 |
gslice_array<T> operator[](const gslice&);
|
| 201 |
+
valarray operator[](const valarray<bool>&) const;
|
| 202 |
mask_array<T> operator[](const valarray<bool>&);
|
| 203 |
+
valarray operator[](const valarray<size_t>&) const;
|
| 204 |
indirect_array<T> operator[](const valarray<size_t>&);
|
| 205 |
|
| 206 |
+
// [valarray.unary], unary operators
|
| 207 |
+
valarray operator+() const;
|
| 208 |
+
valarray operator-() const;
|
| 209 |
+
valarray operator~() const;
|
| 210 |
valarray<bool> operator!() const;
|
| 211 |
|
| 212 |
+
// [valarray.cassign], compound assignment
|
| 213 |
+
valarray& operator*= (const T&);
|
| 214 |
+
valarray& operator/= (const T&);
|
| 215 |
+
valarray& operator%= (const T&);
|
| 216 |
+
valarray& operator+= (const T&);
|
| 217 |
+
valarray& operator-= (const T&);
|
| 218 |
+
valarray& operator^= (const T&);
|
| 219 |
+
valarray& operator&= (const T&);
|
| 220 |
+
valarray& operator|= (const T&);
|
| 221 |
+
valarray& operator<<=(const T&);
|
| 222 |
+
valarray& operator>>=(const T&);
|
| 223 |
|
| 224 |
+
valarray& operator*= (const valarray&);
|
| 225 |
+
valarray& operator/= (const valarray&);
|
| 226 |
+
valarray& operator%= (const valarray&);
|
| 227 |
+
valarray& operator+= (const valarray&);
|
| 228 |
+
valarray& operator-= (const valarray&);
|
| 229 |
+
valarray& operator^= (const valarray&);
|
| 230 |
+
valarray& operator|= (const valarray&);
|
| 231 |
+
valarray& operator&= (const valarray&);
|
| 232 |
+
valarray& operator<<=(const valarray&);
|
| 233 |
+
valarray& operator>>=(const valarray&);
|
| 234 |
|
| 235 |
+
// [valarray.members], member functions
|
| 236 |
void swap(valarray&) noexcept;
|
| 237 |
|
| 238 |
size_t size() const;
|
| 239 |
|
| 240 |
T sum() const;
|
| 241 |
T min() const;
|
| 242 |
T max() const;
|
| 243 |
|
| 244 |
+
valarray shift (int) const;
|
| 245 |
+
valarray cshift(int) const;
|
| 246 |
+
valarray apply(T func(T)) const;
|
| 247 |
+
valarray apply(T func(const T&)) const;
|
| 248 |
void resize(size_t sz, T c = T());
|
| 249 |
};
|
| 250 |
+
|
| 251 |
+
template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
|
| 252 |
}
|
| 253 |
```
|
| 254 |
|
| 255 |
The class template `valarray<T>` is a one-dimensional smart array, with
|
| 256 |
elements numbered sequentially from zero. It is a representation of the
|
| 257 |
+
mathematical concept of an ordered set of values. For convenience, an
|
| 258 |
+
object of type `valarray<T>` is referred to as an “array” throughout the
|
| 259 |
+
remainder of [[numarray]]. The illusion of higher dimensionality may be
|
| 260 |
+
produced by the familiar idiom of computed indices, together with the
|
| 261 |
+
powerful subsetting capabilities provided by the generalized subscript
|
| 262 |
+
operators.[^8]
|
| 263 |
|
| 264 |
An implementation is permitted to qualify any of the functions declared
|
| 265 |
in `<valarray>` as `inline`.
|
| 266 |
|
| 267 |
#### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
|
| 268 |
|
| 269 |
``` cpp
|
| 270 |
valarray();
|
| 271 |
```
|
| 272 |
|
| 273 |
+
*Effects:* Constructs a `valarray` that has zero length.[^9]
|
|
|
|
| 274 |
|
| 275 |
``` cpp
|
| 276 |
+
explicit valarray(size_t n);
|
| 277 |
```
|
| 278 |
|
| 279 |
+
*Effects:* Constructs a `valarray` that has length `n`. Each element of
|
| 280 |
+
the array is value-initialized ([[dcl.init]]).
|
|
|
|
| 281 |
|
| 282 |
``` cpp
|
| 283 |
+
valarray(const T& v, size_t n);
|
| 284 |
```
|
| 285 |
|
| 286 |
+
*Effects:* Constructs a `valarray` that has length `n`. Each element of
|
| 287 |
+
the array is initialized with `v`.
|
|
|
|
| 288 |
|
| 289 |
``` cpp
|
| 290 |
+
valarray(const T* p, size_t n);
|
| 291 |
```
|
| 292 |
|
| 293 |
+
*Requires:* `p` points to an array ([[dcl.array]]) of at least `n`
|
| 294 |
+
elements.
|
| 295 |
+
|
| 296 |
+
*Effects:* Constructs a `valarray` that has length `n`. The values of
|
| 297 |
+
the elements of the array are initialized with the first `n` values
|
| 298 |
+
pointed to by the first argument.[^10]
|
| 299 |
|
| 300 |
``` cpp
|
| 301 |
+
valarray(const valarray& v);
|
| 302 |
```
|
| 303 |
|
| 304 |
+
*Effects:* Constructs a `valarray` that has the same length as `v`. The
|
| 305 |
+
elements are initialized with the values of the corresponding elements
|
| 306 |
+
of `v`.[^11]
|
| 307 |
|
| 308 |
``` cpp
|
| 309 |
+
valarray(valarray&& v) noexcept;
|
| 310 |
```
|
| 311 |
|
| 312 |
+
*Effects:* Constructs a `valarray` that has the same length as `v`. The
|
| 313 |
+
elements are initialized with the values of the corresponding elements
|
| 314 |
+
of `v`.
|
| 315 |
|
| 316 |
*Complexity:* Constant.
|
| 317 |
|
| 318 |
``` cpp
|
| 319 |
valarray(initializer_list<T> il);
|
| 320 |
```
|
| 321 |
|
| 322 |
+
*Effects:* Equivalent to `valarray(il.begin(), il.size())`.
|
| 323 |
|
| 324 |
``` cpp
|
| 325 |
valarray(const slice_array<T>&);
|
| 326 |
valarray(const gslice_array<T>&);
|
| 327 |
valarray(const mask_array<T>&);
|
|
|
|
| 333 |
|
| 334 |
``` cpp
|
| 335 |
~valarray();
|
| 336 |
```
|
| 337 |
|
| 338 |
+
*Effects:* The destructor is applied to every element of `*this`; an
|
| 339 |
+
implementation may return all allocated memory.
|
| 340 |
|
| 341 |
#### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
|
| 342 |
|
| 343 |
``` cpp
|
| 344 |
+
valarray& operator=(const valarray& v);
|
| 345 |
```
|
| 346 |
|
| 347 |
+
*Effects:* Each element of the `*this` array is assigned the value of
|
| 348 |
+
the corresponding element of `v`. If the length of `v` is not equal to
|
| 349 |
+
the length of `*this`, resizes `*this` to make the two arrays the same
|
| 350 |
+
length, as if by calling `resize(v.size())`, before performing the
|
| 351 |
+
assignment.
|
| 352 |
|
| 353 |
+
*Postconditions:* `size() == v.size()`.
|
| 354 |
+
|
| 355 |
+
*Returns:* `*this`.
|
| 356 |
|
| 357 |
``` cpp
|
| 358 |
+
valarray& operator=(valarray&& v) noexcept;
|
| 359 |
```
|
| 360 |
|
| 361 |
*Effects:* `*this` obtains the value of `v`. The value of `v` after the
|
| 362 |
assignment is not specified.
|
| 363 |
|
| 364 |
+
*Returns:* `*this`.
|
| 365 |
+
|
| 366 |
*Complexity:* Linear.
|
| 367 |
|
| 368 |
``` cpp
|
| 369 |
valarray& operator=(initializer_list<T> il);
|
| 370 |
```
|
| 371 |
|
| 372 |
+
*Effects:* Equivalent to: `return *this = valarray(il);`
|
|
|
|
|
|
|
| 373 |
|
| 374 |
``` cpp
|
| 375 |
+
valarray& operator=(const T& v);
|
| 376 |
```
|
| 377 |
|
| 378 |
+
*Effects:* Assigns `v` to each element of `*this`.
|
| 379 |
+
|
| 380 |
+
*Returns:* `*this`.
|
| 381 |
|
| 382 |
``` cpp
|
| 383 |
+
valarray& operator=(const slice_array<T>&);
|
| 384 |
+
valarray& operator=(const gslice_array<T>&);
|
| 385 |
+
valarray& operator=(const mask_array<T>&);
|
| 386 |
+
valarray& operator=(const indirect_array<T>&);
|
| 387 |
```
|
| 388 |
|
| 389 |
*Requires:* The length of the array to which the argument refers equals
|
| 390 |
+
`size()`. The value of an element in the left-hand side of a `valarray`
|
| 391 |
+
assignment operator does not depend on the value of another element in
|
| 392 |
+
that left-hand side.
|
| 393 |
|
| 394 |
These operators allow the results of a generalized subscripting
|
| 395 |
operation to be assigned directly to a `valarray`.
|
| 396 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
#### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
|
| 398 |
|
| 399 |
``` cpp
|
| 400 |
+
const T& operator[](size_t n) const;
|
| 401 |
+
T& operator[](size_t n);
|
| 402 |
```
|
| 403 |
|
| 404 |
+
*Requires:* `n < size()`.
|
|
|
|
| 405 |
|
| 406 |
+
*Returns:* A reference to the corresponding element of the array.
|
|
|
|
|
|
|
| 407 |
|
| 408 |
+
[*Note 1*: The expression `(a[i] = q, a[i]) == q` evaluates to `true`
|
| 409 |
+
for any non-constant `valarray<T> a`, any `T q`, and for any `size_t i`
|
| 410 |
+
such that the value of `i` is less than the length of
|
| 411 |
+
`a`. — *end note*]
|
| 412 |
|
| 413 |
+
*Remarks:* The expression `&a[i+j] == &a[i] + j` evaluates to `true` for
|
| 414 |
+
all `size_t i` and `size_t j` such that `i+j < a.size()`.
|
| 415 |
+
|
| 416 |
+
The expression `&a[i] != &b[j]` evaluates to `true` for any two arrays
|
| 417 |
+
`a` and `b` and for any `size_t i` and `size_t j` such that
|
| 418 |
+
`i < a.size()` and `j < b.size()`.
|
| 419 |
+
|
| 420 |
+
[*Note 2*: This property indicates an absence of aliasing and may be
|
| 421 |
+
used to advantage by optimizing compilers. Compilers may take advantage
|
| 422 |
+
of inlining, constant propagation, loop fusion, tracking of pointers
|
| 423 |
+
obtained from `operator new`, and other techniques to generate efficient
|
| 424 |
+
`valarray`s. — *end note*]
|
| 425 |
|
| 426 |
The reference returned by the subscript operator for an array shall be
|
| 427 |
valid until the member function
|
| 428 |
`resize(size_t, T)` ([[valarray.members]]) is called for that array or
|
| 429 |
until the lifetime of that array ends, whichever happens first.
|
| 430 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
#### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
|
| 432 |
|
| 433 |
The member `operator[]` is overloaded to provide several ways to select
|
| 434 |
sequences of elements from among those controlled by `*this`. Each of
|
| 435 |
these operations returns a subset of the array. The const-qualified
|
|
|
|
| 439 |
`operator=` and other assigning operators to allow selective replacement
|
| 440 |
(slicing) of the controlled sequence. In each case the selected
|
| 441 |
element(s) must exist.
|
| 442 |
|
| 443 |
``` cpp
|
| 444 |
+
valarray operator[](slice slicearr) const;
|
| 445 |
```
|
| 446 |
|
| 447 |
+
*Returns:* A `valarray` containing those elements of the controlled
|
| 448 |
+
sequence designated by `slicearr`.
|
| 449 |
+
|
| 450 |
+
[*Example 1*:
|
| 451 |
|
| 452 |
``` cpp
|
| 453 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 454 |
// v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
|
| 455 |
```
|
| 456 |
|
| 457 |
+
— *end example*]
|
| 458 |
+
|
| 459 |
``` cpp
|
| 460 |
slice_array<T> operator[](slice slicearr);
|
| 461 |
```
|
| 462 |
|
| 463 |
*Returns:* An object that holds references to elements of the controlled
|
| 464 |
sequence selected by `slicearr`.
|
| 465 |
|
| 466 |
+
[*Example 2*:
|
| 467 |
+
|
| 468 |
``` cpp
|
| 469 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 470 |
valarray<char> v1("ABCDE", 5);
|
| 471 |
v0[slice(2, 5, 3)] = v1;
|
| 472 |
// v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
|
| 473 |
```
|
| 474 |
|
| 475 |
+
— *end example*]
|
| 476 |
+
|
| 477 |
``` cpp
|
| 478 |
+
valarray operator[](const gslice& gslicearr) const;
|
| 479 |
```
|
| 480 |
|
| 481 |
+
*Returns:* A `valarray` containing those elements of the controlled
|
| 482 |
+
sequence designated by `gslicearr`.
|
| 483 |
+
|
| 484 |
+
[*Example 3*:
|
| 485 |
|
| 486 |
``` cpp
|
| 487 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 488 |
const size_t lv[] = { 2, 3 };
|
| 489 |
const size_t dv[] = { 7, 2 };
|
| 490 |
const valarray<size_t> len(lv, 2), str(dv, 2);
|
| 491 |
// v0[gslice(3, len, str)] returns
|
| 492 |
// valarray<char>("dfhkmo", 6)
|
| 493 |
```
|
| 494 |
|
| 495 |
+
— *end example*]
|
| 496 |
+
|
| 497 |
``` cpp
|
| 498 |
gslice_array<T> operator[](const gslice& gslicearr);
|
| 499 |
```
|
| 500 |
|
| 501 |
*Returns:* An object that holds references to elements of the controlled
|
| 502 |
sequence selected by `gslicearr`.
|
| 503 |
|
| 504 |
+
[*Example 4*:
|
| 505 |
+
|
| 506 |
``` cpp
|
| 507 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 508 |
+
valarray<char> v1("ABCDEF", 6);
|
| 509 |
const size_t lv[] = { 2, 3 };
|
| 510 |
const size_t dv[] = { 7, 2 };
|
| 511 |
const valarray<size_t> len(lv, 2), str(dv, 2);
|
| 512 |
v0[gslice(3, len, str)] = v1;
|
| 513 |
// v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
|
| 514 |
```
|
| 515 |
|
| 516 |
+
— *end example*]
|
| 517 |
+
|
| 518 |
``` cpp
|
| 519 |
+
valarray operator[](const valarray<bool>& boolarr) const;
|
| 520 |
```
|
| 521 |
|
| 522 |
+
*Returns:* A `valarray` containing those elements of the controlled
|
| 523 |
+
sequence designated by `boolarr`.
|
| 524 |
+
|
| 525 |
+
[*Example 5*:
|
| 526 |
|
| 527 |
``` cpp
|
| 528 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 529 |
const bool vb[] = { false, false, true, true, false, true };
|
| 530 |
// v0[valarray<bool>(vb, 6)] returns
|
| 531 |
// valarray<char>("cdf", 3)
|
| 532 |
```
|
| 533 |
|
| 534 |
+
— *end example*]
|
| 535 |
+
|
| 536 |
``` cpp
|
| 537 |
mask_array<T> operator[](const valarray<bool>& boolarr);
|
| 538 |
```
|
| 539 |
|
| 540 |
*Returns:* An object that holds references to elements of the controlled
|
| 541 |
sequence selected by `boolarr`.
|
| 542 |
|
| 543 |
+
[*Example 6*:
|
| 544 |
+
|
| 545 |
``` cpp
|
| 546 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 547 |
valarray<char> v1("ABC", 3);
|
| 548 |
const bool vb[] = { false, false, true, true, false, true };
|
| 549 |
v0[valarray<bool>(vb, 6)] = v1;
|
| 550 |
// v0 == valarray<char>("abABeCghijklmnop", 16)
|
| 551 |
```
|
| 552 |
|
| 553 |
+
— *end example*]
|
| 554 |
+
|
| 555 |
``` cpp
|
| 556 |
+
valarray operator[](const valarray<size_t>& indarr) const;
|
| 557 |
```
|
| 558 |
|
| 559 |
+
*Returns:* A `valarray` containing those elements of the controlled
|
| 560 |
+
sequence designated by `indarr`.
|
| 561 |
+
|
| 562 |
+
[*Example 7*:
|
| 563 |
|
| 564 |
``` cpp
|
| 565 |
const valarray<char> v0("abcdefghijklmnop", 16);
|
| 566 |
const size_t vi[] = { 7, 5, 2, 3, 8 };
|
| 567 |
// v0[valarray<size_t>(vi, 5)] returns
|
| 568 |
// valarray<char>("hfcdi", 5)
|
| 569 |
```
|
| 570 |
|
| 571 |
+
— *end example*]
|
| 572 |
+
|
| 573 |
``` cpp
|
| 574 |
indirect_array<T> operator[](const valarray<size_t>& indarr);
|
| 575 |
```
|
| 576 |
|
| 577 |
*Returns:* An object that holds references to elements of the controlled
|
| 578 |
sequence selected by `indarr`.
|
| 579 |
|
| 580 |
+
[*Example 8*:
|
| 581 |
+
|
| 582 |
``` cpp
|
| 583 |
valarray<char> v0("abcdefghijklmnop", 16);
|
| 584 |
valarray<char> v1("ABCDE", 5);
|
| 585 |
const size_t vi[] = { 7, 5, 2, 3, 8 };
|
| 586 |
v0[valarray<size_t>(vi, 5)] = v1;
|
| 587 |
// v0 == valarray<char>("abCDeBgAEjklmnop", 16)
|
| 588 |
```
|
| 589 |
|
| 590 |
+
— *end example*]
|
| 591 |
+
|
| 592 |
#### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
|
| 593 |
|
| 594 |
``` cpp
|
| 595 |
+
valarray operator+() const;
|
| 596 |
+
valarray operator-() const;
|
| 597 |
+
valarray operator~() const;
|
| 598 |
valarray<bool> operator!() const;
|
| 599 |
```
|
| 600 |
|
| 601 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 602 |
+
`T` to which the indicated operator can be applied and for which the
|
| 603 |
+
indicated operator returns a value which is of type `T` (`bool` for
|
| 604 |
+
`operator!`) or which may be unambiguously implicitly converted to type
|
| 605 |
+
`T` (`bool` for `operator!`).
|
| 606 |
|
| 607 |
+
*Returns:* A `valarray` whose length is `size()`. Each element of the
|
| 608 |
+
returned array is initialized with the result of applying the indicated
|
| 609 |
+
operator to the corresponding element of the array.
|
|
|
|
| 610 |
|
| 611 |
+
#### `valarray` compound assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
|
| 612 |
|
| 613 |
``` cpp
|
| 614 |
+
valarray& operator*= (const valarray& v);
|
| 615 |
+
valarray& operator/= (const valarray& v);
|
| 616 |
+
valarray& operator%= (const valarray& v);
|
| 617 |
+
valarray& operator+= (const valarray& v);
|
| 618 |
+
valarray& operator-= (const valarray& v);
|
| 619 |
+
valarray& operator^= (const valarray& v);
|
| 620 |
+
valarray& operator&= (const valarray& v);
|
| 621 |
+
valarray& operator|= (const valarray& v);
|
| 622 |
+
valarray& operator<<=(const valarray& v);
|
| 623 |
+
valarray& operator>>=(const valarray& v);
|
| 624 |
```
|
| 625 |
|
| 626 |
+
*Requires:* `size() == v.size()`. Each of these operators may only be
|
| 627 |
+
instantiated for a type `T` if the indicated operator can be applied to
|
| 628 |
+
two operands of type `T`. The value of an element in the left-hand side
|
| 629 |
+
of a valarray compound assignment operator does not depend on the value
|
| 630 |
+
of another element in that left hand side.
|
| 631 |
|
| 632 |
+
*Effects:* Each of these operators performs the indicated operation on
|
| 633 |
+
each of the elements of `*this` and the corresponding element of `v`.
|
| 634 |
|
| 635 |
+
*Returns:* `*this`.
|
|
|
|
|
|
|
| 636 |
|
| 637 |
+
*Remarks:* The appearance of an array on the left-hand side of a
|
| 638 |
+
compound assignment does not invalidate references or pointers.
|
|
|
|
| 639 |
|
| 640 |
``` cpp
|
| 641 |
+
valarray& operator*= (const T& v);
|
| 642 |
+
valarray& operator/= (const T& v);
|
| 643 |
+
valarray& operator%= (const T& v);
|
| 644 |
+
valarray& operator+= (const T& v);
|
| 645 |
+
valarray& operator-= (const T& v);
|
| 646 |
+
valarray& operator^= (const T& v);
|
| 647 |
+
valarray& operator&= (const T& v);
|
| 648 |
+
valarray& operator|= (const T& v);
|
| 649 |
+
valarray& operator<<=(const T& v);
|
| 650 |
+
valarray& operator>>=(const T& v);
|
| 651 |
```
|
| 652 |
|
| 653 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 654 |
+
`T` if the indicated operator can be applied to two operands of type
|
| 655 |
+
`T`.
|
| 656 |
|
| 657 |
+
*Effects:* Each of these operators applies the indicated operation to
|
| 658 |
+
each element of `*this` and `v`.
|
| 659 |
|
| 660 |
+
*Returns:* `*this`
|
| 661 |
|
| 662 |
+
*Remarks:* The appearance of an array on the left-hand side of a
|
| 663 |
+
compound assignment does not invalidate references or pointers to the
|
| 664 |
+
elements of the array.
|
| 665 |
|
| 666 |
#### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
|
| 667 |
|
| 668 |
``` cpp
|
| 669 |
void swap(valarray& v) noexcept;
|
|
|
|
| 684 |
|
| 685 |
``` cpp
|
| 686 |
T sum() const;
|
| 687 |
```
|
| 688 |
|
| 689 |
+
*Requires:* `size() > 0`. This function may only be instantiated for a
|
| 690 |
+
type `T` to which `operator+=` can be applied.
|
|
|
|
| 691 |
|
| 692 |
+
*Returns:* The sum of all the elements of the array. If the array has
|
| 693 |
+
length 1, returns the value of element 0. Otherwise, the returned value
|
| 694 |
+
is calculated by applying `operator+=` to a copy of an element of the
|
| 695 |
+
array and all other elements of the array in an unspecified order.
|
|
|
|
| 696 |
|
| 697 |
``` cpp
|
| 698 |
T min() const;
|
| 699 |
```
|
| 700 |
|
| 701 |
+
*Requires:* `size() > 0`
|
| 702 |
+
|
| 703 |
+
*Returns:* The minimum value contained in `*this`. For an array of
|
| 704 |
+
length 1, the value of element 0 is returned. For all other array
|
| 705 |
+
lengths, the determination is made using `operator<`.
|
| 706 |
|
| 707 |
``` cpp
|
| 708 |
T max() const;
|
| 709 |
```
|
| 710 |
|
| 711 |
+
*Requires:* `size() > 0`.
|
| 712 |
+
|
| 713 |
+
*Returns:* The maximum value contained in `*this`. For an array of
|
| 714 |
+
length 1, the value of element 0 is returned. For all other array
|
| 715 |
+
lengths, the determination is made using `operator<`.
|
| 716 |
|
| 717 |
``` cpp
|
| 718 |
+
valarray shift(int n) const;
|
| 719 |
```
|
| 720 |
|
| 721 |
+
*Returns:* A `valarray` of length `size()`, each of whose elements *I*
|
| 722 |
+
is `(*this)[`*`I`*` + n]` if *`I`*` + n` is non-negative and less than
|
| 723 |
+
`size()`, otherwise `T()`.
|
| 724 |
+
|
| 725 |
+
[*Note 1*: If element zero is taken as the leftmost element, a positive
|
| 726 |
+
value of `n` shifts the elements left `n` places, with zero
|
| 727 |
+
fill. — *end note*]
|
| 728 |
+
|
| 729 |
+
[*Example 1*: If the argument has the value -2, the first two elements
|
| 730 |
+
of the result will be value-initialized ([[dcl.init]]); the third
|
| 731 |
+
element of the result will be assigned the value of the first element of
|
| 732 |
+
the argument; etc. — *end example*]
|
| 733 |
+
|
| 734 |
``` cpp
|
| 735 |
+
valarray cshift(int n) const;
|
| 736 |
```
|
| 737 |
|
| 738 |
+
*Returns:* A `valarray` of length `size()` that is a circular shift of
|
| 739 |
+
`*this`. If element zero is taken as the leftmost element, a
|
| 740 |
+
non-negative value of n shifts the elements circularly left n places and
|
| 741 |
+
a negative value of n shifts the elements circularly right -n places.
|
| 742 |
+
|
| 743 |
``` cpp
|
| 744 |
+
valarray apply(T func(T)) const;
|
| 745 |
+
valarray apply(T func(const T&)) const;
|
| 746 |
```
|
| 747 |
|
| 748 |
+
*Returns:* A `valarray` whose length is `size()`. Each element of the
|
| 749 |
+
returned array is assigned the value returned by applying the argument
|
| 750 |
+
function to the corresponding element of `*this`.
|
| 751 |
+
|
| 752 |
``` cpp
|
| 753 |
void resize(size_t sz, T c = T());
|
| 754 |
```
|
| 755 |
|
| 756 |
+
*Effects:* Changes the length of the `*this` array to `sz` and then
|
| 757 |
+
assigns to each element the value of the second argument. Resizing
|
| 758 |
+
invalidates all pointers and references to elements in the array.
|
| 759 |
+
|
| 760 |
### `valarray` non-member operations <a id="valarray.nonmembers">[[valarray.nonmembers]]</a>
|
| 761 |
|
| 762 |
#### `valarray` binary operators <a id="valarray.binary">[[valarray.binary]]</a>
|
| 763 |
|
| 764 |
``` cpp
|
|
|
|
| 782 |
(const valarray<T>&, const valarray<T>&);
|
| 783 |
template<class T> valarray<T> operator>>
|
| 784 |
(const valarray<T>&, const valarray<T>&);
|
| 785 |
```
|
| 786 |
|
| 787 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 788 |
+
`T` to which the indicated operator can be applied and for which the
|
| 789 |
+
indicated operator returns a value which is of type `T` or which can be
|
| 790 |
+
unambiguously implicitly converted to type `T`. The argument arrays have
|
| 791 |
+
the same length.
|
| 792 |
|
| 793 |
+
*Returns:* A `valarray` whose length is equal to the lengths of the
|
| 794 |
+
argument arrays. Each element of the returned array is initialized with
|
| 795 |
+
the result of applying the indicated operator to the corresponding
|
| 796 |
+
elements of the argument arrays.
|
|
|
|
|
|
|
|
|
|
| 797 |
|
| 798 |
``` cpp
|
| 799 |
template<class T> valarray<T> operator* (const valarray<T>&, const T&);
|
| 800 |
template<class T> valarray<T> operator* (const T&, const valarray<T>&);
|
| 801 |
template<class T> valarray<T> operator/ (const valarray<T>&, const T&);
|
|
|
|
| 816 |
template<class T> valarray<T> operator<<(const T&, const valarray<T>&);
|
| 817 |
template<class T> valarray<T> operator>>(const valarray<T>&, const T&);
|
| 818 |
template<class T> valarray<T> operator>>(const T&, const valarray<T>&);
|
| 819 |
```
|
| 820 |
|
| 821 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 822 |
+
`T` to which the indicated operator can be applied and for which the
|
| 823 |
+
indicated operator returns a value which is of type `T` or which can be
|
| 824 |
unambiguously implicitly converted to type `T`.
|
| 825 |
|
| 826 |
+
*Returns:* A `valarray` whose length is equal to the length of the array
|
| 827 |
+
argument. Each element of the returned array is initialized with the
|
| 828 |
+
result of applying the indicated operator to the corresponding element
|
| 829 |
+
of the array argument and the non-array argument.
|
| 830 |
|
| 831 |
#### `valarray` logical operators <a id="valarray.comparison">[[valarray.comparison]]</a>
|
| 832 |
|
| 833 |
``` cpp
|
| 834 |
template<class T> valarray<bool> operator==
|
|
|
|
| 847 |
(const valarray<T>&, const valarray<T>&);
|
| 848 |
template<class T> valarray<bool> operator||
|
| 849 |
(const valarray<T>&, const valarray<T>&);
|
| 850 |
```
|
| 851 |
|
| 852 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 853 |
+
`T` to which the indicated operator can be applied and for which the
|
| 854 |
+
indicated operator returns a value which is of type `bool` or which can
|
| 855 |
+
be unambiguously implicitly converted to type `bool`. The two array
|
| 856 |
+
arguments have the same length.
|
| 857 |
|
| 858 |
+
*Returns:* A `valarray<bool>` whose length is equal to the length of the
|
| 859 |
+
array arguments. Each element of the returned array is initialized with
|
| 860 |
+
the result of applying the indicated operator to the corresponding
|
| 861 |
+
elements of the argument arrays.
|
|
|
|
|
|
|
|
|
|
| 862 |
|
| 863 |
``` cpp
|
| 864 |
template<class T> valarray<bool> operator==(const valarray<T>&, const T&);
|
| 865 |
template<class T> valarray<bool> operator==(const T&, const valarray<T>&);
|
| 866 |
template<class T> valarray<bool> operator!=(const valarray<T>&, const T&);
|
|
|
|
| 877 |
template<class T> valarray<bool> operator&&(const T&, const valarray<T>&);
|
| 878 |
template<class T> valarray<bool> operator||(const valarray<T>&, const T&);
|
| 879 |
template<class T> valarray<bool> operator||(const T&, const valarray<T>&);
|
| 880 |
```
|
| 881 |
|
| 882 |
+
*Requires:* Each of these operators may only be instantiated for a type
|
| 883 |
+
`T` to which the indicated operator can be applied and for which the
|
| 884 |
+
indicated operator returns a value which is of type `bool` or which can
|
| 885 |
+
be unambiguously implicitly converted to type `bool`.
|
| 886 |
|
| 887 |
+
*Returns:* A `valarray<bool>` whose length is equal to the length of the
|
| 888 |
+
array argument. Each element of the returned array is initialized with
|
| 889 |
+
the result of applying the indicated operator to the corresponding
|
| 890 |
+
element of the array and the non-array argument.
|
| 891 |
|
| 892 |
#### `valarray` transcendentals <a id="valarray.transcend">[[valarray.transcend]]</a>
|
| 893 |
|
| 894 |
``` cpp
|
| 895 |
template<class T> valarray<T> abs (const valarray<T>&);
|
|
|
|
| 914 |
template<class T> valarray<T> sqrt (const valarray<T>&);
|
| 915 |
template<class T> valarray<T> tan (const valarray<T>&);
|
| 916 |
template<class T> valarray<T> tanh (const valarray<T>&);
|
| 917 |
```
|
| 918 |
|
| 919 |
+
*Requires:* Each of these functions may only be instantiated for a type
|
| 920 |
+
`T` to which a unique function with the indicated name can be applied
|
| 921 |
+
(unqualified). This function shall return a value which is of type `T`
|
| 922 |
+
or which can be unambiguously implicitly converted to type `T`.
|
| 923 |
|
| 924 |
#### `valarray` specialized algorithms <a id="valarray.special">[[valarray.special]]</a>
|
| 925 |
|
| 926 |
``` cpp
|
| 927 |
template <class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
|
| 928 |
```
|
| 929 |
|
| 930 |
+
*Effects:* Equivalent to `x.swap(y)`.
|
| 931 |
|
| 932 |
### Class `slice` <a id="class.slice">[[class.slice]]</a>
|
| 933 |
|
| 934 |
#### Class `slice` overview <a id="class.slice.overview">[[class.slice.overview]]</a>
|
| 935 |
|
|
|
|
| 946 |
};
|
| 947 |
}
|
| 948 |
```
|
| 949 |
|
| 950 |
The `slice` class represents a BLAS-like slice from an array. Such a
|
| 951 |
+
slice is specified by a starting index, a length, and a stride.[^12]
|
| 952 |
|
| 953 |
#### `slice` constructors <a id="cons.slice">[[cons.slice]]</a>
|
| 954 |
|
| 955 |
``` cpp
|
| 956 |
slice();
|
|
|
|
| 961 |
The default constructor is equivalent to `slice(0, 0, 0)`. A default
|
| 962 |
constructor is provided only to permit the declaration of arrays of
|
| 963 |
slices. The constructor with arguments for a slice takes a start,
|
| 964 |
length, and stride parameter.
|
| 965 |
|
| 966 |
+
[*Example 1*: `slice(3, 8, 2)` constructs a slice which selects
|
| 967 |
+
elements 3, 5, 7, ... 17 from an array. — *end example*]
|
| 968 |
|
| 969 |
#### `slice` access functions <a id="slice.access">[[slice.access]]</a>
|
| 970 |
|
| 971 |
``` cpp
|
| 972 |
size_t start() const;
|
|
|
|
| 984 |
|
| 985 |
``` cpp
|
| 986 |
namespace std {
|
| 987 |
template <class T> class slice_array {
|
| 988 |
public:
|
| 989 |
+
using value_type = T;
|
| 990 |
|
| 991 |
void operator= (const valarray<T>&) const;
|
| 992 |
void operator*= (const valarray<T>&) const;
|
| 993 |
void operator/= (const valarray<T>&) const;
|
| 994 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1018 |
```
|
| 1019 |
|
| 1020 |
It has reference semantics to a subset of an array specified by a
|
| 1021 |
`slice` object.
|
| 1022 |
|
| 1023 |
+
[*Example 1*: The expression `a[slice(1, 5, 3)] = b;` has the effect of
|
| 1024 |
+
assigning the elements of `b` to a slice of the elements in `a`. For the
|
| 1025 |
+
slice shown, the elements selected from `a` are 1, 4, ...,
|
| 1026 |
+
13. — *end example*]
|
| 1027 |
|
| 1028 |
#### `slice_array` assignment <a id="slice.arr.assign">[[slice.arr.assign]]</a>
|
| 1029 |
|
| 1030 |
``` cpp
|
| 1031 |
void operator=(const valarray<T>&) const;
|
|
|
|
| 1034 |
|
| 1035 |
These assignment operators have reference semantics, assigning the
|
| 1036 |
values of the argument array elements to selected elements of the
|
| 1037 |
`valarray<T>` object to which the `slice_array` object refers.
|
| 1038 |
|
| 1039 |
+
#### `slice_array` compound assignment <a id="slice.arr.comp.assign">[[slice.arr.comp.assign]]</a>
|
| 1040 |
|
| 1041 |
``` cpp
|
| 1042 |
void operator*= (const valarray<T>&) const;
|
| 1043 |
void operator/= (const valarray<T>&) const;
|
| 1044 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1049 |
void operator|= (const valarray<T>&) const;
|
| 1050 |
void operator<<=(const valarray<T>&) const;
|
| 1051 |
void operator>>=(const valarray<T>&) const;
|
| 1052 |
```
|
| 1053 |
|
| 1054 |
+
These compound assignments have reference semantics, applying the
|
| 1055 |
indicated operation to the elements of the argument array and selected
|
| 1056 |
elements of the `valarray<T>` object to which the `slice_array` object
|
| 1057 |
refers.
|
| 1058 |
|
| 1059 |
#### `slice_array` fill function <a id="slice.arr.fill">[[slice.arr.fill]]</a>
|
|
|
|
| 1093 |
building multidimensional array classes using the `valarray` template,
|
| 1094 |
which is one-dimensional. The set of one-dimensional index values
|
| 1095 |
specified by a `gslice` are $$k = s + \sum_j i_j d_j$$ where the
|
| 1096 |
multidimensional indices iⱼ range in value from 0 to lᵢⱼ - 1.
|
| 1097 |
|
| 1098 |
+
[*Example 1*:
|
| 1099 |
+
|
| 1100 |
The `gslice` specification
|
| 1101 |
|
| 1102 |
``` cpp
|
| 1103 |
start = 3
|
| 1104 |
length = {2, 4, 3}
|
| 1105 |
stride = {19, 4, 1}
|
| 1106 |
```
|
| 1107 |
|
| 1108 |
yields the sequence of one-dimensional indices
|
|
|
|
| 1109 |
$$k = 3 + (0, 1) \times 19 + (0, 1, 2, 3) \times 4 + (0, 1, 2) \times 1$$
|
|
|
|
| 1110 |
which are ordered as shown in the following table:
|
| 1111 |
|
| 1112 |
That is, the highest-ordered index turns fastest.
|
| 1113 |
|
| 1114 |
+
— *end example*]
|
| 1115 |
+
|
| 1116 |
It is possible to have degenerate generalized slices in which an address
|
| 1117 |
is repeated.
|
| 1118 |
|
| 1119 |
+
[*Example 2*:
|
| 1120 |
+
|
| 1121 |
If the stride parameters in the previous example are changed to {1, 1,
|
| 1122 |
1}, the first few elements of the resulting sequence of indices will be
|
| 1123 |
|
| 1124 |
+
— *end example*]
|
| 1125 |
+
|
| 1126 |
If a degenerate slice is used as the argument to the non-`const` version
|
| 1127 |
+
of `operator[](const gslice&)`, the behavior is undefined.
|
| 1128 |
|
| 1129 |
#### `gslice` constructors <a id="gslice.cons">[[gslice.cons]]</a>
|
| 1130 |
|
| 1131 |
``` cpp
|
| 1132 |
gslice();
|
|
|
|
| 1160 |
|
| 1161 |
``` cpp
|
| 1162 |
namespace std {
|
| 1163 |
template <class T> class gslice_array {
|
| 1164 |
public:
|
| 1165 |
+
using value_type = T;
|
| 1166 |
|
| 1167 |
void operator= (const valarray<T>&) const;
|
| 1168 |
void operator*= (const valarray<T>&) const;
|
| 1169 |
void operator/= (const valarray<T>&) const;
|
| 1170 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1209 |
|
| 1210 |
These assignment operators have reference semantics, assigning the
|
| 1211 |
values of the argument array elements to selected elements of the
|
| 1212 |
`valarray<T>` object to which the `gslice_array` refers.
|
| 1213 |
|
| 1214 |
+
#### `gslice_array` compound assignment <a id="gslice.array.comp.assign">[[gslice.array.comp.assign]]</a>
|
| 1215 |
|
| 1216 |
``` cpp
|
| 1217 |
void operator*= (const valarray<T>&) const;
|
| 1218 |
void operator/= (const valarray<T>&) const;
|
| 1219 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1224 |
void operator|= (const valarray<T>&) const;
|
| 1225 |
void operator<<=(const valarray<T>&) const;
|
| 1226 |
void operator>>=(const valarray<T>&) const;
|
| 1227 |
```
|
| 1228 |
|
| 1229 |
+
These compound assignments have reference semantics, applying the
|
| 1230 |
indicated operation to the elements of the argument array and selected
|
| 1231 |
elements of the `valarray<T>` object to which the `gslice_array` object
|
| 1232 |
refers.
|
| 1233 |
|
| 1234 |
#### `gslice_array` fill function <a id="gslice.array.fill">[[gslice.array.fill]]</a>
|
|
|
|
| 1247 |
|
| 1248 |
``` cpp
|
| 1249 |
namespace std {
|
| 1250 |
template <class T> class mask_array {
|
| 1251 |
public:
|
| 1252 |
+
using value_type = T;
|
| 1253 |
|
| 1254 |
void operator= (const valarray<T>&) const;
|
| 1255 |
void operator*= (const valarray<T>&) const;
|
| 1256 |
void operator/= (const valarray<T>&) const;
|
| 1257 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1293 |
|
| 1294 |
These assignment operators have reference semantics, assigning the
|
| 1295 |
values of the argument array elements to selected elements of the
|
| 1296 |
`valarray<T>` object to which it refers.
|
| 1297 |
|
| 1298 |
+
#### `mask_array` compound assignment <a id="mask.array.comp.assign">[[mask.array.comp.assign]]</a>
|
| 1299 |
|
| 1300 |
``` cpp
|
| 1301 |
void operator*= (const valarray<T>&) const;
|
| 1302 |
void operator/= (const valarray<T>&) const;
|
| 1303 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1308 |
void operator|= (const valarray<T>&) const;
|
| 1309 |
void operator<<=(const valarray<T>&) const;
|
| 1310 |
void operator>>=(const valarray<T>&) const;
|
| 1311 |
```
|
| 1312 |
|
| 1313 |
+
These compound assignments have reference semantics, applying the
|
| 1314 |
indicated operation to the elements of the argument array and selected
|
| 1315 |
elements of the `valarray<T>` object to which the mask object refers.
|
| 1316 |
|
| 1317 |
#### `mask_array` fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
|
| 1318 |
|
|
|
|
| 1330 |
|
| 1331 |
``` cpp
|
| 1332 |
namespace std {
|
| 1333 |
template <class T> class indirect_array {
|
| 1334 |
public:
|
| 1335 |
+
using value_type = T;
|
| 1336 |
|
| 1337 |
void operator= (const valarray<T>&) const;
|
| 1338 |
void operator*= (const valarray<T>&) const;
|
| 1339 |
void operator/= (const valarray<T>&) const;
|
| 1340 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1380 |
`valarray<T>` object to which it refers.
|
| 1381 |
|
| 1382 |
If the `indirect_array` specifies an element in the `valarray<T>` object
|
| 1383 |
to which it refers more than once, the behavior is undefined.
|
| 1384 |
|
| 1385 |
+
[*Example 1*:
|
| 1386 |
+
|
| 1387 |
``` cpp
|
| 1388 |
int addr[] = {2, 3, 1, 4, 4};
|
| 1389 |
valarray<size_t> indirect(addr, 5);
|
| 1390 |
valarray<double> a(0., 10), b(1., 5);
|
| 1391 |
a[indirect] = b;
|
| 1392 |
```
|
| 1393 |
|
| 1394 |
results in undefined behavior since element 4 is specified twice in the
|
| 1395 |
indirection.
|
| 1396 |
|
| 1397 |
+
— *end example*]
|
| 1398 |
+
|
| 1399 |
+
#### `indirect_array` compound assignment <a id="indirect.array.comp.assign">[[indirect.array.comp.assign]]</a>
|
| 1400 |
|
| 1401 |
``` cpp
|
| 1402 |
void operator*= (const valarray<T>&) const;
|
| 1403 |
void operator/= (const valarray<T>&) const;
|
| 1404 |
void operator%= (const valarray<T>&) const;
|
|
|
|
| 1409 |
void operator|= (const valarray<T>&) const;
|
| 1410 |
void operator<<=(const valarray<T>&) const;
|
| 1411 |
void operator>>=(const valarray<T>&) const;
|
| 1412 |
```
|
| 1413 |
|
| 1414 |
+
These compound assignments have reference semantics, applying the
|
| 1415 |
indicated operation to the elements of the argument array and selected
|
| 1416 |
elements of the `valarray<T>` object to which the `indirect_array`
|
| 1417 |
object refers.
|
| 1418 |
|
| 1419 |
If the `indirect_array` specifies an element in the `valarray<T>` object
|
|
|
|
| 1427 |
|
| 1428 |
This function has reference semantics, assigning the value of its
|
| 1429 |
argument to the elements of the `valarray<T>` object to which the
|
| 1430 |
`indirect_array` object refers.
|
| 1431 |
|
| 1432 |
+
### `valarray` range access <a id="valarray.range">[[valarray.range]]</a>
|
| 1433 |
|
| 1434 |
In the `begin` and `end` function templates that follow, *unspecified*1
|
| 1435 |
is a type that meets the requirements of a mutable random access
|
| 1436 |
+
iterator ([[random.access.iterators]]) and of a contiguous iterator (
|
| 1437 |
+
[[iterator.requirements.general]]) whose `value_type` is the template
|
| 1438 |
+
parameter `T` and whose `reference` type is `T&`. *unspecified*2 is a
|
| 1439 |
+
type that meets the requirements of a constant random access iterator (
|
| 1440 |
+
[[random.access.iterators]]) and of a contiguous iterator (
|
| 1441 |
+
[[iterator.requirements.general]]) whose `value_type` is the template
|
| 1442 |
+
parameter `T` and whose `reference` type is `const T&`.
|
| 1443 |
|
| 1444 |
The iterators returned by `begin` and `end` for an array are guaranteed
|
| 1445 |
to be valid until the member function `resize(size_t, T)` (
|
| 1446 |
[[valarray.members]]) is called for that array or until the lifetime of
|
| 1447 |
that array ends, whichever happens first.
|
|
|
|
| 1449 |
``` cpp
|
| 1450 |
template <class T> unspecified{1} begin(valarray<T>& v);
|
| 1451 |
template <class T> unspecified{2} begin(const valarray<T>& v);
|
| 1452 |
```
|
| 1453 |
|
| 1454 |
+
*Returns:* An iterator referencing the first value in the array.
|
| 1455 |
|
| 1456 |
``` cpp
|
| 1457 |
template <class T> unspecified{1} end(valarray<T>& v);
|
| 1458 |
template <class T> unspecified{2} end(const valarray<T>& v);
|
| 1459 |
```
|
| 1460 |
|
| 1461 |
+
*Returns:* An iterator referencing one past the last value in the array.
|
|
|
|
| 1462 |
|