From Jason Turner

[numerics]

Large diff (223.1 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp9aiw4xbu/{from.md → to.md} +2765 -985
tmp/tmp9aiw4xbu/{from.md → to.md} RENAMED
@@ -5,29 +5,41 @@
5
  This Clause describes components that C++programs may use to perform
6
  seminumerical operations.
7
 
8
  The following subclauses describe components for complex number types,
9
  random number generation, numeric ( *n*-at-a-time) arrays, generalized
10
- numeric algorithms, and facilities included from the ISO C library, as
11
- summarized in Table  [[tab:numerics.lib.summary]].
12
 
13
  **Table: Numerics library summary** <a id="tab:numerics.lib.summary">[tab:numerics.lib.summary]</a>
14
 
15
  | Subclause | | Header |
16
  | ------------------------ | ------------------------------ | ------------ |
 
17
  | [[numeric.requirements]] | Requirements | |
18
- | [[cfenv]] | Floating-Point Environment | `<cfenv>` |
19
- | [[complex.numbers]] | Complex Numbers | `<complex>` |
20
  | [[rand]] | Random number generation | `<random>` |
21
  | [[numarray]] | Numeric arrays | `<valarray>` |
22
  | [[numeric.ops]] | Generalized numeric operations | `<numeric>` |
23
- | [[c.math]] | C library | `<cmath>` |
24
- | | | `<ctgmath>` |
25
- | | | `<tgmath.h>` |
26
- | | | `<cstdlib>` |
27
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  ## Numeric type requirements <a id="numeric.requirements">[[numeric.requirements]]</a>
30
 
31
  The `complex` and `valarray` components are parameterized by the type of
32
  information they contain and manipulate. A C++program shall instantiate
33
  these components only with a type `T` that satisfies the following
@@ -43,100 +55,121 @@ requirements:[^1]
43
  - If `T` is a class, it has a public destructor;
44
  - If `T` is a class, it has a public assignment operator whose signature
45
  is either `T& T::operator=(const T&)` or `T& T::operator=(T)`
46
  - If `T` is a class, its assignment operator, copy and default
47
  constructors, and destructor shall correspond to each other in the
48
- following sense: Initialization of raw storage using the default
49
- constructor, followed by assignment, is semantically equivalent to
50
- initialization of raw storage using the copy constructor. Destruction
51
- of an object, followed by initialization of its raw storage using the
52
- copy constructor, is semantically equivalent to assignment to the
53
- original object. This rule states that there shall not be any subtle
 
 
 
 
 
 
 
54
  differences in the semantics of initialization versus assignment. This
55
  gives an implementation considerable flexibility in how arrays are
56
- initialized. An implementation is allowed to initialize a `valarray`
57
- by allocating storage using the `new` operator (which implies a call
58
- to the default constructor for each element) and then assigning each
59
- element its value. Or the implementation can allocate raw storage and
60
- use the copy constructor to initialize each element. If the
61
- distinction between initialization and assignment is important for a
62
- class, or if it fails to satisfy any of the other conditions listed
63
- above, the programmer should use `vector` ([[vector]]) instead of
64
- `valarray` for that class;
 
 
 
 
65
  - If `T` is a class, it does not overload unary `operator&`.
66
 
67
  If any operation on `T` throws an exception the effects are undefined.
68
 
69
  In addition, many member and related functions of `valarray<T>` can be
70
  successfully instantiated and will exhibit well-defined behavior if and
71
  only if `T` satisfies additional requirements specified for each such
72
  member or related function.
73
 
74
- It is valid to instantiate `valarray<complex>`, but `operator>()` will
75
- not be successfully instantiated for `valarray<complex>` operands, since
76
- `complex` does not have any ordering operators.
 
77
 
78
  ## The floating-point environment <a id="cfenv">[[cfenv]]</a>
79
 
80
  ### Header `<cfenv>` synopsis <a id="cfenv.syn">[[cfenv.syn]]</a>
81
 
82
  ``` cpp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  namespace std {
84
  // types
85
- typedef object type fenv_t;
86
- typedef integer type fexcept_t;
87
 
88
  // functions
89
  int feclearexcept(int except);
90
  int fegetexceptflag(fexcept_t* pflag, int except);
91
  int feraiseexcept(int except);
92
  int fesetexceptflag(const fexcept_t* pflag, int except);
93
  int fetestexcept(int except);
94
 
95
- int fegetround(void);
96
  int fesetround(int mode);
97
 
98
  int fegetenv(fenv_t* penv);
99
  int feholdexcept(fenv_t* penv);
100
  int fesetenv(const fenv_t* penv);
101
  int feupdateenv(const fenv_t* penv);
102
  }
103
  ```
104
 
105
- The header also defines the macros:
106
-
107
- ``` cpp
108
- FE_ALL_EXCEPT
109
- FE_DIVBYZERO
110
- FE_INEXACT
111
- FE_INVALID
112
- FE_OVERFLOW
113
- FE_UNDERFLOW
114
-
115
- FE_DOWNWARD
116
- FE_TONEAREST
117
- FE_TOWARDZERO
118
- FE_UPWARD
119
-
120
- FE_DFL_ENV
121
- ```
122
-
123
- The header defines all functions, types, and macros the same as Clause
124
- 7.6 of the C standard.
125
 
126
  The floating-point environment has thread storage duration (
127
  [[basic.stc.thread]]). The initial state for a thread’s floating-point
128
  environment is the state of the floating-point environment of the thread
129
- that constructs the corresponding `std::thread` object (
130
- [[thread.thread.class]]) at the time it constructed the object. That is,
131
- the child thread gets the floating-point state of the parent thread at
132
- the time of the child’s creation.
 
133
 
134
  A separate floating-point environment shall be maintained for each
135
  thread. Each function accesses the environment corresponding to its
136
  calling thread.
137
 
 
 
138
  ## Complex numbers <a id="complex.numbers">[[complex.numbers]]</a>
139
 
140
  The header `<complex>` defines a class template, and numerous functions
141
  for representing and manipulating complex numbers.
142
 
@@ -146,19 +179,19 @@ specializations `complex<float>`, `complex<double>`, and
146
  `complex<long double>` are literal types ([[basic.types]]).
147
 
148
  If the result of a function is not mathematically defined or not in the
149
  range of representable values for its type, the behavior is undefined.
150
 
151
- If `z` is an lvalue expression of type *cv* `std::complex<T>` then:
152
 
153
  - the expression `reinterpret_cast<cv T(&)[2]>(z)` shall be well-formed,
154
  - `reinterpret_cast<cv T(&)[2]>(z)[0]` shall designate the real part of
155
  `z`, and
156
  - `reinterpret_cast<cv T(&)[2]>(z)[1]` shall designate the imaginary
157
  part of `z`.
158
 
159
- Moreover, if `a` is an expression of type `cv std::complex<T>*` and the
160
  expression `a[i]` is well-defined for an integer expression `i`, then:
161
 
162
  - `reinterpret_cast<cv T*>(a)[2*i]` shall designate the real part of
163
  `a[i]`, and
164
  - `reinterpret_cast<cv T*>(a)[2*i + 1]` shall designate the imaginary
@@ -171,11 +204,11 @@ namespace std {
171
  template<class T> class complex;
172
  template<> class complex<float>;
173
  template<> class complex<double>;
174
  template<> class complex<long double>;
175
 
176
- // [complex.ops], operators:
177
  template<class T>
178
  complex<T> operator+(const complex<T>&, const complex<T>&);
179
  template<class T> complex<T> operator+(const complex<T>&, const T&);
180
  template<class T> complex<T> operator+(const T&, const complex<T>&);
181
 
@@ -212,11 +245,11 @@ namespace std {
212
 
213
  template<class T, class charT, class traits>
214
  basic_ostream<charT, traits>&
215
  operator<<(basic_ostream<charT, traits>&, const complex<T>&);
216
 
217
- // [complex.value.ops], values:
218
  template<class T> constexpr T real(const complex<T>&);
219
  template<class T> constexpr T imag(const complex<T>&);
220
 
221
  template<class T> T abs(const complex<T>&);
222
  template<class T> T arg(const complex<T>&);
@@ -224,11 +257,11 @@ namespace std {
224
 
225
  template<class T> complex<T> conj(const complex<T>&);
226
  template<class T> complex<T> proj(const complex<T>&);
227
  template<class T> complex<T> polar(const T&, const T& = 0);
228
 
229
- // [complex.transcendentals], transcendentals:
230
  template<class T> complex<T> acos(const complex<T>&);
231
  template<class T> complex<T> asin(const complex<T>&);
232
  template<class T> complex<T> atan(const complex<T>&);
233
 
234
  template<class T> complex<T> acosh(const complex<T>&);
@@ -249,11 +282,11 @@ namespace std {
249
  template<class T> complex<T> sinh (const complex<T>&);
250
  template<class T> complex<T> sqrt (const complex<T>&);
251
  template<class T> complex<T> tan (const complex<T>&);
252
  template<class T> complex<T> tanh (const complex<T>&);
253
 
254
- // [complex.literals], complex literals:
255
  inline namespace literals {
256
  inline namespace complex_literals {
257
  constexpr complex<long double> operator""il(long double);
258
  constexpr complex<long double> operator""il(unsigned long long);
259
  constexpr complex<double> operator""i(long double);
@@ -270,11 +303,11 @@ namespace std {
270
  ``` cpp
271
  namespace std {
272
  template<class T>
273
  class complex {
274
  public:
275
- typedef T value_type;
276
 
277
  constexpr complex(const T& re = T(), const T& im = T());
278
  constexpr complex(const complex&);
279
  template<class X> constexpr complex(const complex<X>&);
280
 
@@ -306,11 +339,11 @@ components, `real()` and `imag()`, of a complex number.
306
 
307
  ``` cpp
308
  namespace std {
309
  template<> class complex<float> {
310
  public:
311
- typedef float value_type;
312
 
313
  constexpr complex(float re = 0.0f, float im = 0.0f);
314
  constexpr explicit complex(const complex<double>&);
315
  constexpr explicit complex(const complex<long double>&);
316
 
@@ -333,11 +366,11 @@ namespace std {
333
  template<class X> complex<float>& operator/=(const complex<X>&);
334
  };
335
 
336
  template<> class complex<double> {
337
  public:
338
- typedef double value_type;
339
 
340
  constexpr complex(double re = 0.0, double im = 0.0);
341
  constexpr complex(const complex<float>&);
342
  constexpr explicit complex(const complex<long double>&);
343
 
@@ -360,11 +393,11 @@ namespace std {
360
  template<class X> complex<double>& operator/=(const complex<X>&);
361
  };
362
 
363
  template<> class complex<long double> {
364
  public:
365
- typedef long double value_type;
366
 
367
  constexpr complex(long double re = 0.0L, long double im = 0.0L);
368
  constexpr complex(const complex<float>&);
369
  constexpr complex(const complex<double>&);
370
 
@@ -395,11 +428,11 @@ namespace std {
395
  template<class T> constexpr complex(const T& re = T(), const T& im = T());
396
  ```
397
 
398
  *Effects:* Constructs an object of class `complex`.
399
 
400
- `real() == re && imag() == im`.
401
 
402
  ``` cpp
403
  constexpr T real() const;
404
  ```
405
 
@@ -503,73 +536,67 @@ template<class X> complex<T>& operator/=(const complex<X>& rhs);
503
 
504
  ``` cpp
505
  template<class T> complex<T> operator+(const complex<T>& lhs);
506
  ```
507
 
508
- *Remarks:* unary operator.
509
-
510
  *Returns:* `complex<T>(lhs)`.
511
 
 
 
512
  ``` cpp
513
- template<class T>
514
- complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
515
  template<class T> complex<T> operator+(const complex<T>& lhs, const T& rhs);
516
  template<class T> complex<T> operator+(const T& lhs, const complex<T>& rhs);
517
  ```
518
 
519
  *Returns:* `complex<T>(lhs) += rhs`.
520
 
521
  ``` cpp
522
  template<class T> complex<T> operator-(const complex<T>& lhs);
523
  ```
524
 
525
- *Remarks:* unary operator.
526
-
527
  *Returns:* `complex<T>(-lhs.real(),-lhs.imag())`.
528
 
 
 
529
  ``` cpp
530
- template<class T>
531
- complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
532
  template<class T> complex<T> operator-(const complex<T>& lhs, const T& rhs);
533
  template<class T> complex<T> operator-(const T& lhs, const complex<T>& rhs);
534
  ```
535
 
536
  *Returns:* `complex<T>(lhs) -= rhs`.
537
 
538
  ``` cpp
539
- template<class T>
540
- complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
541
  template<class T> complex<T> operator*(const complex<T>& lhs, const T& rhs);
542
  template<class T> complex<T> operator*(const T& lhs, const complex<T>& rhs);
543
  ```
544
 
545
  *Returns:* `complex<T>(lhs) *= rhs`.
546
 
547
  ``` cpp
548
- template<class T>
549
- complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
550
  template<class T> complex<T> operator/(const complex<T>& lhs, const T& rhs);
551
  template<class T> complex<T> operator/(const T& lhs, const complex<T>& rhs);
552
  ```
553
 
554
  *Returns:* `complex<T>(lhs) /= rhs`.
555
 
556
  ``` cpp
557
- template<class T>
558
- constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
559
  template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
560
  template<class T> constexpr bool operator==(const T& lhs, const complex<T>& rhs);
561
  ```
562
 
563
  *Returns:* `lhs.real() == rhs.real() && lhs.imag() == rhs.imag()`.
564
 
565
  *Remarks:* The imaginary part is assumed to be `T()`, or 0.0, for the
566
  `T` arguments.
567
 
568
  ``` cpp
569
- template<class T>
570
- constexpr bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
571
  template<class T> constexpr bool operator!=(const complex<T>& lhs, const T& rhs);
572
  template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs);
573
  ```
574
 
575
  *Returns:* `rhs.real() != lhs.real() || rhs.imag() != lhs.imag()`.
@@ -578,16 +605,16 @@ template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs)
578
  template<class T, class charT, class traits>
579
  basic_istream<charT, traits>&
580
  operator>>(basic_istream<charT, traits>& is, complex<T>& x);
581
  ```
582
 
 
 
583
  *Effects:* Extracts a complex number `x` of the form: `u`, `(u)`, or
584
  `(u,v)`, where `u` is the real part and `v` is the imaginary
585
  part ([[istream.formatted]]).
586
 
587
- *Requires:* The input values shall be convertible to `T`.
588
-
589
  If bad input is encountered, calls `is.setstate(ios_base::failbit)`
590
  (which may throw `ios::failure` ([[iostate.flags]])).
591
 
592
  *Returns:* `is`.
593
 
@@ -599,31 +626,27 @@ the same for each of the simpler extractions.
599
  template<class T, class charT, class traits>
600
  basic_ostream<charT, traits>&
601
  operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
602
  ```
603
 
604
- *Effects:* inserts the complex number `x` onto the stream `o` as if it
605
  were implemented as follows:
606
 
607
  ``` cpp
608
- template<class T, class charT, class traits>
609
- basic_ostream<charT, traits>&
610
- operator<<(basic_ostream<charT, traits>& o, const complex<T>& x) {
611
  basic_ostringstream<charT, traits> s;
612
  s.flags(o.flags());
613
  s.imbue(o.getloc());
614
  s.precision(o.precision());
615
  s << '(' << x.real() << "," << x.imag() << ')';
616
  return o << s.str();
617
- }
618
  ```
619
 
620
- *Note:* In a locale in which comma is used as a decimal point character,
621
- the use of comma as a field separator can be ambiguous. Inserting
622
- `std::showpoint` into the output stream forces all outputs to show an
623
- explicit decimal point character; as a result, all inserted sequences of
624
- complex numbers can be extracted unambiguously.
625
 
626
  ### `complex` value operations <a id="complex.value.ops">[[complex.value.ops]]</a>
627
 
628
  ``` cpp
629
  template<class T> constexpr T real(const complex<T>& x);
@@ -672,10 +695,13 @@ template<class T> complex<T> proj(const complex<T>& x);
672
 
673
  ``` cpp
674
  template<class T> complex<T> polar(const T& rho, const T& theta = 0);
675
  ```
676
 
 
 
 
677
  *Returns:* The `complex` value corresponding to a complex number whose
678
  magnitude is `rho` and whose phase angle is `theta`.
679
 
680
  ### `complex` transcendentals <a id="complex.transcendentals">[[complex.transcendentals]]</a>
681
 
@@ -741,44 +767,42 @@ template<class T> complex<T> cosh(const complex<T>& x);
741
 
742
  ``` cpp
743
  template<class T> complex<T> exp(const complex<T>& x);
744
  ```
745
 
746
- *Returns:* The complex base e exponential of `x`.
747
 
748
  ``` cpp
749
  template<class T> complex<T> log(const complex<T>& x);
750
  ```
751
 
752
- *Remarks:* the branch cuts are along the negative real axis.
 
 
753
 
754
- *Returns:* The complex natural (base e) logarithm of `x`, in the range
755
- of a strip mathematically unbounded along the real axis and in the
756
- interval \[`-i times pi`, `i times pi`\] along the imaginary axis. When
757
- `x` is a negative real number, `imag(log(x))` is pi.
758
 
759
  ``` cpp
760
  template<class T> complex<T> log10(const complex<T>& x);
761
  ```
762
 
763
- *Remarks:* the branch cuts are along the negative real axis.
764
-
765
- *Returns:* The complex common (base 10) logarithm of `x`, defined as
766
  `log(x) / log(10)`.
767
 
 
 
768
  ``` cpp
769
- template<class T>
770
- complex<T> pow(const complex<T>& x, const complex<T>& y);
771
  template<class T> complex<T> pow(const complex<T>& x, const T& y);
772
  template<class T> complex<T> pow(const T& x, const complex<T>& y);
773
  ```
774
 
775
- *Remarks:* the branch cuts are along the negative real axis.
776
-
777
- *Returns:* The complex power of base `x` raised to the `y`-th power,
778
  defined as `exp(y * log(x))`. The value returned for `pow(0, 0)` is
779
- implementation-defined.
 
 
780
 
781
  ``` cpp
782
  template<class T> complex<T> sin(const complex<T>& x);
783
  ```
784
 
@@ -792,16 +816,16 @@ template<class T> complex<T> sinh (const complex<T>& x);
792
 
793
  ``` cpp
794
  template<class T> complex<T> sqrt(const complex<T>& x);
795
  ```
796
 
797
- *Remarks:* the branch cuts are along the negative real axis.
798
-
799
  *Returns:* The complex square root of `x`, in the range of the right
800
  half-plane. If the argument is a negative real number, the value
801
  returned lies on the positive imaginary axis.
802
 
 
 
803
  ``` cpp
804
  template<class T> complex<T> tan(const complex<T>& x);
805
  ```
806
 
807
  *Returns:* The complex tangent of `x`.
@@ -870,29 +894,27 @@ constexpr complex<float> operator""if(long double d);
870
  constexpr complex<float> operator""if(unsigned long long d);
871
  ```
872
 
873
  *Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
874
 
875
- ### Header `<ccomplex>` <a id="ccmplx">[[ccmplx]]</a>
876
-
877
- The header behaves as if it simply includes the header `<complex>`.
878
-
879
  ## Random number generation <a id="rand">[[rand]]</a>
880
 
881
  This subclause defines a facility for generating (pseudo-)random
882
  numbers.
883
 
884
  In addition to a few utilities, four categories of entities are
885
- described: *uniform random number generators*, *random number engines*,
886
  *random number engine adaptors*, and *random number distributions*.
887
  These categorizations are applicable to types that satisfy the
888
  corresponding requirements, to objects instantiated from such types, and
889
- to templates producing such types when instantiated. These entities are
890
- specified in such a way as to permit the binding of any uniform random
891
- number generator object `e` as the argument to any random number
892
- distribution object `d`, thus producing a zero-argument function object
893
- such as given by `bind(d,e)`.
 
 
894
 
895
  Each of the entities specified via this subclause has an associated
896
  arithmetic type ([[basic.fundamental]]) identified as `result_type`.
897
  With `T` as the `result_type` thus associated with such an entity, that
898
  entity is characterized:
@@ -914,75 +936,78 @@ Throughout this subclause [[rand]], the effect of instantiating a
914
  template:
915
 
916
  Throughout this subclause [[rand]], phrases of the form “`x` is an
917
  iterator of a specific kind” shall be interpreted as equivalent to the
918
  more formal requirement that “`x` is a value of a type satisfying the
919
- requirements of the specified iterator type.
920
 
921
  Throughout this subclause [[rand]], any constructor that can be called
922
  with a single argument and that satisfies a requirement specified in
923
  this subclause shall be declared `explicit`.
924
 
925
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
926
 
927
  A *seed sequence* is an object that consumes a sequence of
928
  integer-valued data and produces a requested number of unsigned integer
929
- values i, 0 ≤ i < 2³², based on the consumed data. Such an object
930
- provides a mechanism to avoid replication of streams of random variates.
931
- This can be useful, for example, in applications requiring large numbers
932
- of random number engines.
 
 
933
 
934
  A class `S` satisfies the requirements of a seed sequence if the
935
  expressions shown in Table  [[tab:SeedSequence]] are valid and have the
936
  indicated semantics, and if `S` also satisfies all other requirements of
937
  this section [[rand.req.seedseq]]. In that Table and throughout this
938
  section:
939
 
940
- #### Uniform random number generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
941
 
942
- A *uniform random number generator* `g` of type `G` is a function object
943
  returning unsigned integer values such that each value in the range of
944
- possible results has (ideally) equal probability of being returned. The
945
- degree to which `g`’s results approximate the ideal is often determined
946
- statistically.
947
 
948
- A class `G` satisfies the requirements of a *uniform random number
 
 
 
949
  generator* if the expressions shown in Table 
950
- [[tab:UniformRandomNumberGenerator]] are valid and have the indicated
951
  semantics, and if `G` also satisfies all other requirements of this
952
  section [[rand.req.urng]]. In that Table and throughout this section:
953
 
954
  The following relation shall hold: `G::min() < G::max()`.
955
 
956
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
957
 
958
  A *random number engine* (commonly shortened to *engine*) `e` of type
959
- `E` is a uniform random number generator that additionally meets the
960
- requirements (*e.g.*, for seeding and for input/output) specified in
961
- this section.
962
 
963
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
964
  construction, `e` has an initial state e₀. An engine’s state may be
965
  established via a constructor, a `seed` function, assignment, or a
966
  suitable `operator>>`.
967
 
968
  `E`’s specification shall define:
969
 
970
- A class `E` that satisfies the requirements of a uniform random number
971
  generator ([[rand.req.urng]]) also satisfies the requirements of a
972
  *random number engine* if the expressions shown in Table 
973
  [[tab:RandomEngine]] are valid and have the indicated semantics, and if
974
  `E` also satisfies all other requirements of this section
975
  [[rand.req.eng]]. In that Table and throughout this section:
976
 
977
  where `charT` and `traits` are constrained according to Clause 
978
  [[strings]] and Clause  [[input.output]].
979
 
980
  `E` shall meet the requirements of `CopyConstructible` (Table 
981
- [[copyconstructible]]) and `CopyAssignable` (Table  [[copyassignable]])
982
- types. These operations shall each be of complexity no worse than
983
- 𝑂(\mbox{size of state}).
984
 
985
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
986
 
987
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
988
  of type `A` is a random number engine that takes values produced by some
@@ -1014,11 +1039,11 @@ A::A(result_type s);
1014
  ```
1015
 
1016
  *Effects:* The base engine is initialized with `s`.
1017
 
1018
  ``` cpp
1019
- template<class Sseq> void A::A(Sseq& q);
1020
  ```
1021
 
1022
  *Effects:* The base engine is initialized with `q`.
1023
 
1024
  ``` cpp
@@ -1066,12 +1091,12 @@ In that Table and throughout this section,
1066
 
1067
  where `charT` and `traits` are constrained according to Clauses 
1068
  [[strings]] and [[input.output]].
1069
 
1070
  `D` shall satisfy the requirements of `CopyConstructible` (Table 
1071
- [[copyconstructible]]) and `CopyAssignable` (Table  [[copyassignable]])
1072
- types.
1073
 
1074
  The sequence of numbers produced by repeated invocations of `d(g)` shall
1075
  be independent of any invocation of `os << d` or of any `const` member
1076
  function of `D` between any of the invocations `d(g)`.
1077
 
@@ -1085,12 +1110,13 @@ It is unspecified whether `D::param_type` is declared as a (nested)
1085
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
1086
  `D::param_type` are in the form of `typedef`s for convenience of
1087
  exposition only.
1088
 
1089
  `P` shall satisfy the requirements of `CopyConstructible` (Table 
1090
- [[copyconstructible]]), `CopyAssignable` (Table  [[copyassignable]]),
1091
- and `EqualityComparable` (Table  [[equalitycomparable]]) types.
 
1092
 
1093
  For each of the constructors of `D` taking arguments corresponding to
1094
  parameters of the distribution, `P` shall have a corresponding
1095
  constructor subject to the same requirements and taking arguments
1096
  identical in number, type, and default values. Moreover, for each of the
@@ -1099,20 +1125,19 @@ of the distribution, `P` shall have a corresponding member function with
1099
  the identical name, type, and semantics.
1100
 
1101
  `P` shall have a declaration of the form
1102
 
1103
  ``` cpp
1104
- typedef D distribution_type;
1105
  ```
1106
 
1107
  ### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
1108
 
1109
  ``` cpp
1110
  #include <initializer_list>
1111
 
1112
  namespace std {
1113
-
1114
  // [rand.eng.lcong], class template linear_congruential_engine
1115
  template<class UIntType, UIntType a, UIntType c, UIntType m>
1116
  class linear_congruential_engine;
1117
 
1118
  // [rand.eng.mers], class template mersenne_twister_engine
@@ -1137,30 +1162,31 @@ namespace std {
1137
  // [rand.adapt.shuf], class template shuffle_order_engine
1138
  template<class Engine, size_t k>
1139
  class shuffle_order_engine;
1140
 
1141
  // [rand.predef], engines and engine adaptors with predefined parameters
1142
- typedef see below minstd_rand0;
1143
- typedef see below minstd_rand;
1144
- typedef see below mt19937;
1145
- typedef see below mt19937_64;
1146
- typedef see below ranlux24_base;
1147
- typedef see below ranlux48_base;
1148
- typedef see below ranlux24;
1149
- typedef see below ranlux48;
1150
- typedef see below knuth_b;
1151
- typedef see below default_random_engine;
 
1152
 
1153
  // [rand.device], class random_device
1154
  class random_device;
1155
 
1156
  // [rand.util.seedseq], class seed_seq
1157
  class seed_seq;
1158
 
1159
  // [rand.util.canonical], function template generate_canonical
1160
- template<class RealType, size_t bits, class URNG>
1161
- RealType generate_canonical(URNG& g);
1162
 
1163
  // [rand.dist.uni.int], class template uniform_int_distribution
1164
  template<class IntType = int>
1165
  class uniform_int_distribution;
1166
 
@@ -1236,12 +1262,11 @@ namespace std {
1236
  class piecewise_constant_distribution;
1237
 
1238
  // [rand.dist.samp.plinear], class template piecewise_linear_distribution
1239
  template<class RealType = double>
1240
  class piecewise_linear_distribution;
1241
-
1242
- } // namespace std
1243
  ```
1244
 
1245
  ### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
1246
 
1247
  Each type instantiated from a class template specified in this section 
@@ -1252,25 +1277,30 @@ Except where specified otherwise, the complexity of each function
1252
  specified in this section  [[rand.eng]] is constant.
1253
 
1254
  Except where specified otherwise, no function described in this section 
1255
  [[rand.eng]] throws an exception.
1256
 
 
 
 
 
 
1257
  Descriptions are provided in this section  [[rand.eng]] only for engine
1258
- operations that are not described in [[rand.req.eng]] or for
1259
- operations where there is additional semantic information. In
1260
- particular, declarations for copy constructors, for copy assignment
1261
- operators, for streaming operators, and for equality and inequality
1262
- operators are not shown in the synopses.
1263
 
1264
  Each template specified in this section  [[rand.eng]] requires one or
1265
  more relationships, involving the value(s) of its non-type template
1266
  parameter(s), to hold. A program instantiating any of these templates is
1267
  ill-formed if any such required relationship fails to hold.
1268
 
1269
  For every random number engine and for every random number engine
1270
- adaptor `X` defined in this sub-clause ([[rand.eng]]) and in
1271
- sub-clause  [[rand.adapt]]:
1272
 
1273
  - if the constructor
1274
  ``` cpp
1275
  template <class Sseq> explicit X(Sseq& q);
1276
  ```
@@ -1299,15 +1329,14 @@ algorithm is a modular linear function of the form
1299
  TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
1300
  GA(xᵢ) = xᵢ₊₁.
1301
 
1302
  ``` cpp
1303
  template<class UIntType, UIntType a, UIntType c, UIntType m>
1304
- class linear_congruential_engine
1305
- {
1306
  public:
1307
  // types
1308
- typedef UIntType result_type;
1309
 
1310
  // engine characteristics
1311
  static constexpr result_type multiplier = a;
1312
  static constexpr result_type increment = c;
1313
  static constexpr result_type modulus = m;
@@ -1327,11 +1356,14 @@ public:
1327
  };
1328
  ```
1329
 
1330
  If the template parameter `m` is 0, the modulus m used throughout this
1331
  section  [[rand.eng.lcong]] is `numeric_limits<result_type>::max()` plus
1332
- 1. m need not be representable as a value of type `result_type`.
 
 
 
1333
 
1334
  If the template parameter `m` is not 0, the following relations shall
1335
  hold: `a < m` and `c < m`.
1336
 
1337
  The textual representation consists of the value of xᵢ.
@@ -1366,11 +1398,11 @@ sequence X of n values of the type delivered by `x`; all subscripts
1366
  applied to X are to be taken modulo n.
1367
 
1368
  The transition algorithm employs a twisted generalized feedback shift
1369
  register defined by shift values n and m, a twist value r, and a
1370
  conditional xor-mask a. To improve the uniformity of the result, the
1371
- bits of the raw shift register are additionally *tempered* (*i.e.*,
1372
  scrambled) according to a bit-scrambling matrix defined by values
1373
  u, d, s, b, t, c, and ℓ.
1374
 
1375
  The state transition is performed as follows:
1376
 
@@ -1383,15 +1415,14 @@ z₁, z₂, z₃, z₄ as follows, then delivers z₄ as its result:
1383
  ``` cpp
1384
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
1385
  UIntType a, size_t u, UIntType d, size_t s,
1386
  UIntType b, size_t t,
1387
  UIntType c, size_t l, UIntType f>
1388
- class mersenne_twister_engine
1389
- {
1390
  public:
1391
  // types
1392
- typedef UIntType result_type;
1393
 
1394
  // engine characteristics
1395
  static constexpr size_t word_size = w;
1396
  static constexpr size_t state_size = n;
1397
  static constexpr size_t shift_size = m;
@@ -1468,24 +1499,23 @@ all subscripts applied to X are to be taken modulo r. The state xᵢ
1468
  additionally consists of an integer c (known as the *carry*) whose value
1469
  is either 0 or 1.
1470
 
1471
  The state transition is performed as follows:
1472
 
1473
- This algorithm corresponds to a modular linear function of the form
1474
- TA(xᵢ) = (a ⋅ xᵢ) mod b, where b is of the form mʳ - mˢ + 1 and
1475
- a = b - (b-1) / m.
1476
 
1477
  The generation algorithm is given by GA(xᵢ) = y, where y is the value
1478
  produced as a result of advancing the engine’s state as described above.
1479
 
1480
  ``` cpp
1481
  template<class UIntType, size_t w, size_t s, size_t r>
1482
- class subtract_with_carry_engine
1483
- {
1484
  public:
1485
  // types
1486
- typedef UIntType result_type;
1487
 
1488
  // engine characteristics
1489
  static constexpr size_t word_size = w;
1490
  static constexpr size_t short_lag = s;
1491
  static constexpr size_t long_lag = r;
@@ -1547,19 +1577,24 @@ X₋₁ is then 0, sets c to 1; otherwise sets c to 0.
1547
  ### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
1548
 
1549
  #### In general <a id="rand.adapt.general">[[rand.adapt.general]]</a>
1550
 
1551
  Each type instantiated from a class template specified in this section 
1552
- [[rand.eng]] satisfies the requirements of a random number engine
1553
  adaptor ([[rand.req.adapt]]) type.
1554
 
1555
  Except where specified otherwise, the complexity of each function
1556
  specified in this section  [[rand.adapt]] is constant.
1557
 
1558
  Except where specified otherwise, no function described in this section 
1559
  [[rand.adapt]] throws an exception.
1560
 
 
 
 
 
 
1561
  Descriptions are provided in this section  [[rand.adapt]] only for
1562
  adaptor operations that are not described in section  [[rand.req.adapt]]
1563
  or for operations where there is additional semantic information. In
1564
  particular, declarations for copy constructors, for copy assignment
1565
  operators, for streaming operators, and for equality and inequality
@@ -1587,15 +1622,14 @@ state eⱼ to eⱼ₊₁.
1587
  The generation algorithm yields the value returned by the last
1588
  invocation of `e()` while advancing `e`’s state as described above.
1589
 
1590
  ``` cpp
1591
  template<class Engine, size_t p, size_t r>
1592
- class discard_block_engine
1593
- {
1594
  public:
1595
  // types
1596
- typedef typename Engine::result_type result_type;
1597
 
1598
  // engine characteristics
1599
  static constexpr size_t block_size = p;
1600
  static constexpr size_t used_block = r;
1601
  static constexpr result_type min() { return Engine::min(); }
@@ -1642,11 +1676,12 @@ state eᵢ of its base engine `e`; the size of the state is the size of
1642
  e’s state.
1643
 
1644
  The transition and generation algorithms are described in terms of the
1645
  following integral constants:
1646
 
1647
- The relation w = n₀ w₀ + (n - n₀)(w₀ + 1) always holds.
 
1648
 
1649
  The transition algorithm is carried out by invoking `e()` as often as
1650
  needed to obtain n₀ values less than y₀ + `e.min()` and n - n₀ values
1651
  less than y₁ + `e.min()` .
1652
 
@@ -1666,15 +1701,14 @@ for (k = n₀; k \neq n; k += 1) {
1666
  }
1667
  ```
1668
 
1669
  ``` cpp
1670
  template<class Engine, size_t w, class UIntType>
1671
- class independent_bits_engine
1672
- {
1673
  public:
1674
  // types
1675
- typedef UIntType result_type;
1676
 
1677
  // engine characteristics
1678
  static constexpr result_type min() { return 0; }
1679
  static constexpr result_type max() { return 2^w - 1; }
1680
 
@@ -1722,15 +1756,14 @@ transition is performed as follows:
1722
  The generation algorithm yields the last value of `Y` produced while
1723
  advancing `e`’s state as described above.
1724
 
1725
  ``` cpp
1726
  template<class Engine, size_t k>
1727
- class shuffle_order_engine
1728
- {
1729
  public:
1730
  // types
1731
- typedef typename Engine::result_type result_type;
1732
 
1733
  // engine characteristics
1734
  static constexpr size_t table_size = k;
1735
  static constexpr result_type min() { return Engine::min(); }
1736
  static constexpr result_type max() { return Engine::max(); }
@@ -1752,12 +1785,12 @@ public:
1752
  // property functions
1753
  const Engine& base() const noexcept { return e; };
1754
 
1755
  private:
1756
  Engine e; // exposition only
1757
- result_type Y; // exposition only
1758
  result_type V[k]; // exposition only
 
1759
  };
1760
  ```
1761
 
1762
  The following relation shall hold: `0 < k`.
1763
 
@@ -1770,124 +1803,121 @@ each constructor that is not a copy constructor initializes
1770
  successive invocations of `e()`.
1771
 
1772
  ### Engines and engine adaptors with predefined parameters <a id="rand.predef">[[rand.predef]]</a>
1773
 
1774
  ``` cpp
1775
- typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
1776
- minstd_rand0;
1777
  ```
1778
 
1779
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1780
  default-constructed object of type `minstd_rand0` shall produce the
1781
  value 1043618065.
1782
 
1783
  ``` cpp
1784
- typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
1785
- minstd_rand;
1786
  ```
1787
 
1788
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1789
  default-constructed object of type `minstd_rand` shall produce the value
1790
  399268537.
1791
 
1792
  ``` cpp
1793
- typedef mersenne_twister_engine<uint_fast32_t,
1794
- 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>
1795
- mt19937;
1796
  ```
1797
 
1798
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1799
  default-constructed object of type `mt19937` shall produce the value
1800
  4123659995.
1801
 
1802
  ``` cpp
1803
- typedef mersenne_twister_engine<uint_fast64_t,
 
1804
  64,312,156,31,0xb5026f5aa96619e9,29,
1805
  0x5555555555555555,17,
1806
  0x71d67fffeda60000,37,
1807
  0xfff7eee000000000,43,
1808
- 6364136223846793005>
1809
- mt19937_64;
1810
  ```
1811
 
1812
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1813
  default-constructed object of type `mt19937_64` shall produce the value
1814
  9981545732273789042.
1815
 
1816
  ``` cpp
1817
- typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>
1818
- ranlux24_base;
1819
  ```
1820
 
1821
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1822
  default-constructed object of type `ranlux24_base` shall produce the
1823
  value 7937952.
1824
 
1825
  ``` cpp
1826
- typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>
1827
- ranlux48_base;
1828
  ```
1829
 
1830
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1831
  default-constructed object of type `ranlux48_base` shall produce the
1832
  value 61839128582725.
1833
 
1834
  ``` cpp
1835
- typedef discard_block_engine<ranlux24_base, 223, 23>
1836
- ranlux24;
1837
  ```
1838
 
1839
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1840
  default-constructed object of type `ranlux24` shall produce the value
1841
  9901578.
1842
 
1843
  ``` cpp
1844
- typedef discard_block_engine<ranlux48_base, 389, 11>
1845
- ranlux48;
1846
  ```
1847
 
1848
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1849
  default-constructed object of type `ranlux48` shall produce the value
1850
  249142670248501.
1851
 
1852
  ``` cpp
1853
- typedef shuffle_order_engine<minstd_rand0,256>
1854
- knuth_b;
1855
  ```
1856
 
1857
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1858
  default-constructed object of type `knuth_b` shall produce the value
1859
  1112339016.
1860
 
1861
  ``` cpp
1862
- typedef implementation-defined
1863
- default_random_engine;
1864
  ```
1865
 
1866
- The choice of engine type named by this `typedef` is
1867
- implementation-defined. The implementation may select this type on the
1868
- basis of performance, size, quality, or any combination of such factors,
1869
- so as to provide at least acceptable engine behavior for relatively
1870
- casual, inexpert, and/or lightweight use. Because different
1871
- implementations may select different underlying engine types, code that
1872
- uses this `typedef` need not generate identical sequences across
1873
- implementations.
 
 
1874
 
1875
  ### Class `random_device` <a id="rand.device">[[rand.device]]</a>
1876
 
1877
- A `random_device` uniform random number generator produces
1878
- non-deterministic random numbers.
1879
 
1880
- If implementation limitations prevent generating non-deterministic
1881
- random numbers, the implementation may employ a random number engine.
1882
 
1883
  ``` cpp
1884
- class random_device
1885
- {
1886
  public:
1887
  // types
1888
- typedef unsigned int result_type;
1889
 
1890
  // generator characteristics
1891
  static constexpr result_type min() { return numeric_limits<result_type>::min(); }
1892
  static constexpr result_type max() { return numeric_limits<result_type>::max(); }
1893
 
@@ -1908,15 +1938,15 @@ public:
1908
 
1909
  ``` cpp
1910
  explicit random_device(const string& token = implementation-defined);
1911
  ```
1912
 
1913
- *Effects:* Constructs a `random_device` non-deterministic uniform random
1914
- number generator object. The semantics and default value of the `token`
1915
- parameter are implementation-defined.[^3]
1916
 
1917
- *Throws:* A value of an implementation-defined type derived from
1918
  `exception` if the `random_device` could not be initialized.
1919
 
1920
  ``` cpp
1921
  double entropy() const noexcept;
1922
  ```
@@ -1927,27 +1957,26 @@ returned by `operator()`, in the range `min()` to log₂( `max()`+1).
1927
 
1928
  ``` cpp
1929
  result_type operator()();
1930
  ```
1931
 
1932
- *Returns:* A non-deterministic random value, uniformly distributed
1933
- between `min()` and `max()`, inclusive. It is implementation-defined how
1934
- these values are generated.
1935
 
1936
- *Throws:* A value of an implementation-defined type derived from
1937
  `exception` if a random number could not be obtained.
1938
 
1939
  ### Utilities <a id="rand.util">[[rand.util]]</a>
1940
 
1941
  #### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
1942
 
1943
  ``` cpp
1944
- class seed_seq
1945
- {
1946
  public:
1947
  // types
1948
- typedef uint_least32_t result_type;
1949
 
1950
  // constructors
1951
  seed_seq();
1952
  template<class T>
1953
  seed_seq(initializer_list<T> il);
@@ -1957,11 +1986,11 @@ public:
1957
  // generating functions
1958
  template<class RandomAccessIterator>
1959
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1960
 
1961
  // property functions
1962
- size_t size() const;
1963
  template<class OutputIterator>
1964
  void param(OutputIterator dest) const;
1965
 
1966
  // no copy functions
1967
  seed_seq(const seed_seq& ) = delete;
@@ -2011,12 +2040,11 @@ for( InputIterator s = begin; s != end; ++s)
2011
  template<class RandomAccessIterator>
2012
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
2013
  ```
2014
 
2015
  *Requires:* `RandomAccessIterator` shall meet the requirements of a
2016
- mutable random access iterator
2017
- (Table  [[tab:iterator.random.access.requirements]]) type. Moreover,
2018
  `iterator_traits<RandomAccessIterator>::value_type` shall denote an
2019
  unsigned integer type capable of accommodating 32-bit quantities.
2020
 
2021
  *Effects:* Does nothing if `begin == end`. Otherwise, with
2022
  s = `v.size()` and n = `end` - `begin`, fills the supplied range
@@ -2027,29 +2055,26 @@ $x \, \xor \, (x \, \rightshift \, 27)$:
2027
 
2028
  *Throws:* What and when `RandomAccessIterator` operations of `begin` and
2029
  `end` throw.
2030
 
2031
  ``` cpp
2032
- size_t size() const;
2033
  ```
2034
 
2035
  *Returns:* The number of 32-bit units that would be returned by a call
2036
  to `param()`.
2037
 
2038
- *Throws:* Nothing.
2039
-
2040
  *Complexity:* Constant time.
2041
 
2042
  ``` cpp
2043
  template<class OutputIterator>
2044
  void param(OutputIterator dest) const;
2045
  ```
2046
 
2047
  *Requires:* `OutputIterator` shall satisfy the requirements of an output
2048
- iterator (Table  [[tab:iterator.output.requirements]]) type. Moreover,
2049
- the expression `*dest = rt` shall be valid for a value `rt` of type
2050
- `result_type`.
2051
 
2052
  *Effects:* Copies the sequence of prepared 32-bit units to the given
2053
  destination, as if by executing the following statement:
2054
 
2055
  ``` cpp
@@ -2060,22 +2085,23 @@ copy(v.begin(), v.end(), dest);
2060
 
2061
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
2062
 
2063
  Each function instantiated from the template described in this section 
2064
  [[rand.util.canonical]] maps the result of one or more invocations of a
2065
- supplied uniform random number generator `g` to one member of the
2066
- specified `RealType` such that, if the values gᵢ produced by `g` are
2067
- uniformly distributed, the instantiation’s results tⱼ, 0 ≤ tⱼ < 1, are
2068
- distributed as uniformly as possible as specified below.
2069
 
2070
- Obtaining a value in this way can be a useful step in the process of
2071
- transforming a value generated by a uniform random number generator into
2072
- a value that can be delivered by a random number distribution.
 
2073
 
2074
  ``` cpp
2075
- template<class RealType, size_t bits, class URNG>
2076
- RealType generate_canonical(URNG& g);
2077
  ```
2078
 
2079
  *Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
2080
  where b[^5] is the lesser of `numeric_limits<RealType>::digits` and
2081
  `bits`, and R is the value of `g.max()` - `g.min()` + 1.
@@ -2103,11 +2129,11 @@ for operations where there is additional semantic information. In
2103
  particular, declarations for copy constructors, for copy assignment
2104
  operators, for streaming operators, and for equality and inequality
2105
  operators are not shown in the synopses.
2106
 
2107
  The algorithms for producing each of the specified distributions are
2108
- implementation-defined.
2109
 
2110
  The value of each probability density function p(z) and of each discrete
2111
  probability function P(zᵢ) specified in this section is 0 everywhere
2112
  outside its stated domain.
2113
 
@@ -2121,27 +2147,26 @@ probability function $$%
2121
  P(i\,|\,a,b) = 1 / (b - a + 1)
2122
  \; \mbox{.}$$
2123
 
2124
  ``` cpp
2125
  template<class IntType = int>
2126
- class uniform_int_distribution
2127
- {
2128
  public:
2129
  // types
2130
- typedef IntType result_type;
2131
- typedef unspecified param_type;
2132
 
2133
  // constructors and reset functions
2134
  explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits<IntType>::max());
2135
  explicit uniform_int_distribution(const param_type& parm);
2136
  void reset();
2137
 
2138
  // generating functions
2139
- template<class URNG>
2140
- result_type operator()(URNG& g);
2141
- template<class URNG>
2142
- result_type operator()(URNG& g, const param_type& parm);
2143
 
2144
  // property functions
2145
  result_type a() const;
2146
  result_type b() const;
2147
  param_type param() const;
@@ -2180,29 +2205,31 @@ A `uniform_real_distribution` random number distribution produces random
2180
  numbers x, a ≤ x < b, distributed according to the constant probability
2181
  density function $$%
2182
  p(x\,|\,a,b) = 1 / (b - a)
2183
  \; \mbox{.}$$
2184
 
 
 
 
2185
  ``` cpp
2186
  template<class RealType = double>
2187
- class uniform_real_distribution
2188
- {
2189
  public:
2190
  // types
2191
- typedef RealType result_type;
2192
- typedef unspecified param_type;
2193
 
2194
  // constructors and reset functions
2195
  explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
2196
  explicit uniform_real_distribution(const param_type& parm);
2197
  void reset();
2198
 
2199
  // generating functions
2200
- template<class URNG>
2201
- result_type operator()(URNG& g);
2202
- template<class URNG>
2203
- result_type operator()(URNG& g, const param_type& parm);
2204
 
2205
  // property functions
2206
  result_type a() const;
2207
  result_type b() const;
2208
  param_type param() const;
@@ -2247,27 +2274,26 @@ values b distributed according to the discrete probability function $$%
2247
  1-p & \mbox{if} & b = \tcode{false}
2248
  \end{array}\right.
2249
  \; \mbox{.}$$
2250
 
2251
  ``` cpp
2252
- class bernoulli_distribution
2253
- {
2254
  public:
2255
  // types
2256
- typedef bool result_type;
2257
- typedef unspecified param_type;
2258
 
2259
  // constructors and reset functions
2260
  explicit bernoulli_distribution(double p = 0.5);
2261
  explicit bernoulli_distribution(const param_type& parm);
2262
  void reset();
2263
 
2264
  // generating functions
2265
- template<class URNG>
2266
- result_type operator()(URNG& g);
2267
- template<class URNG>
2268
- result_type operator()(URNG& g, const param_type& parm);
2269
 
2270
  // property functions
2271
  double p() const;
2272
  param_type param() const;
2273
  void param(const param_type& parm);
@@ -2301,27 +2327,26 @@ $$%
2301
  = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i}
2302
  \; \mbox{.}$$
2303
 
2304
  ``` cpp
2305
  template<class IntType = int>
2306
- class binomial_distribution
2307
- {
2308
  public:
2309
  // types
2310
- typedef IntType result_type;
2311
- typedef unspecified param_type;
2312
 
2313
  // constructors and reset functions
2314
  explicit binomial_distribution(IntType t = 1, double p = 0.5);
2315
  explicit binomial_distribution(const param_type& parm);
2316
  void reset();
2317
 
2318
  // generating functions
2319
- template<class URNG>
2320
- result_type operator()(URNG& g);
2321
- template<class URNG>
2322
- result_type operator()(URNG& g, const param_type& parm);
2323
 
2324
  // property functions
2325
  IntType t() const;
2326
  double p() const;
2327
  param_type param() const;
@@ -2363,27 +2388,26 @@ $$%
2363
  = p \cdot (1-p)^{i}
2364
  \; \mbox{.}$$
2365
 
2366
  ``` cpp
2367
  template<class IntType = int>
2368
- class geometric_distribution
2369
- {
2370
  public:
2371
  // types
2372
- typedef IntType result_type;
2373
- typedef unspecified param_type;
2374
 
2375
  // constructors and reset functions
2376
  explicit geometric_distribution(double p = 0.5);
2377
  explicit geometric_distribution(const param_type& parm);
2378
  void reset();
2379
 
2380
  // generating functions
2381
- template<class URNG>
2382
- result_type operator()(URNG& g);
2383
- template<class URNG>
2384
- result_type operator()(URNG& g, const param_type& parm);
2385
 
2386
  // property functions
2387
  double p() const;
2388
  param_type param() const;
2389
  void param(const param_type& parm);
@@ -2415,29 +2439,31 @@ random integers i ≥ 0 distributed according to the discrete probability
2415
  function $$%
2416
  P(i\,|\,k,p)
2417
  = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i
2418
  \; \mbox{.}$$
2419
 
 
 
 
2420
  ``` cpp
2421
  template<class IntType = int>
2422
- class negative_binomial_distribution
2423
- {
2424
  public:
2425
  // types
2426
- typedef IntType result_type;
2427
- typedef unspecified param_type;
2428
 
2429
  // constructor and reset functions
2430
  explicit negative_binomial_distribution(IntType k = 1, double p = 0.5);
2431
  explicit negative_binomial_distribution(const param_type& parm);
2432
  void reset();
2433
 
2434
  // generating functions
2435
- template<class URNG>
2436
- result_type operator()(URNG& g);
2437
- template<class URNG>
2438
- result_type operator()(URNG& g, const param_type& parm);
2439
 
2440
  // property functions
2441
  IntType k() const;
2442
  double p() const;
2443
  param_type param() const;
@@ -2487,23 +2513,23 @@ distribution’s *mean* .
2487
  template<class IntType = int>
2488
  class poisson_distribution
2489
  {
2490
  public:
2491
  // types
2492
- typedef IntType result_type;
2493
- typedef unspecified param_type;
2494
 
2495
  // constructors and reset functions
2496
  explicit poisson_distribution(double mean = 1.0);
2497
  explicit poisson_distribution(const param_type& parm);
2498
  void reset();
2499
 
2500
  // generating functions
2501
- template<class URNG>
2502
- result_type operator()(URNG& g);
2503
- template<class URNG>
2504
- result_type operator()(URNG& g, const param_type& parm);
2505
 
2506
  // property functions
2507
  double mean() const;
2508
  param_type param() const;
2509
  void param(const param_type& parm);
@@ -2537,27 +2563,26 @@ $$%
2537
  = \lambda e^{-\lambda x}
2538
  \; \mbox{.}$$
2539
 
2540
  ``` cpp
2541
  template<class RealType = double>
2542
- class exponential_distribution
2543
- {
2544
  public:
2545
  // types
2546
- typedef RealType result_type;
2547
- typedef unspecified param_type;
2548
 
2549
  // constructors and reset functions
2550
  explicit exponential_distribution(RealType lambda = 1.0);
2551
  explicit exponential_distribution(const param_type& parm);
2552
  void reset();
2553
 
2554
  // generating functions
2555
- template<class URNG>
2556
- result_type operator()(URNG& g);
2557
- template<class URNG>
2558
- result_type operator()(URNG& g, const param_type& parm);
2559
 
2560
  // property functions
2561
  RealType lambda() const;
2562
  param_type param() const;
2563
  void param(const param_type& parm);
@@ -2570,11 +2595,11 @@ public:
2570
  explicit exponential_distribution(RealType lambda = 1.0);
2571
  ```
2572
 
2573
  *Requires:* 0 < `lambda`.
2574
 
2575
- *Effects:* Constructs a `exponential_distribution` object; `lambda`
2576
  corresponds to the parameter of the distribution.
2577
 
2578
  ``` cpp
2579
  RealType lambda() const;
2580
  ```
@@ -2592,27 +2617,26 @@ $$%
2592
  \, \cdot \, x^{\, \alpha-1}
2593
  \; \mbox{.}$$
2594
 
2595
  ``` cpp
2596
  template<class RealType = double>
2597
- class gamma_distribution
2598
- {
2599
  public:
2600
  // types
2601
- typedef RealType result_type;
2602
- typedef unspecified param_type;
2603
 
2604
  // constructors and reset functions
2605
  explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0);
2606
  explicit gamma_distribution(const param_type& parm);
2607
  void reset();
2608
 
2609
  // generating functions
2610
- template<class URNG>
2611
- result_type operator()(URNG& g);
2612
- template<class URNG>
2613
- result_type operator()(URNG& g, const param_type& parm);
2614
 
2615
  // property functions
2616
  RealType alpha() const;
2617
  RealType beta() const;
2618
  param_type param() const;
@@ -2656,27 +2680,26 @@ $$%
2656
  \cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
2657
  \; \mbox{.}$$
2658
 
2659
  ``` cpp
2660
  template<class RealType = double>
2661
- class weibull_distribution
2662
- {
2663
  public:
2664
  // types
2665
- typedef RealType result_type;
2666
- typedef unspecified param_type;
2667
 
2668
  // constructor and reset functions
2669
  explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0);
2670
  explicit weibull_distribution(const param_type& parm);
2671
  void reset();
2672
 
2673
  // generating functions
2674
- template<class URNG>
2675
- result_type operator()(URNG& g);
2676
- template<class URNG>
2677
- result_type operator()(URNG& g, const param_type& parm);
2678
 
2679
  // property functions
2680
  RealType a() const;
2681
  RealType b() const;
2682
  param_type param() const;
@@ -2721,27 +2744,26 @@ function[^6] $$%
2721
  \right)
2722
  \; \mbox{.}$$
2723
 
2724
  ``` cpp
2725
  template<class RealType = double>
2726
- class extreme_value_distribution
2727
- {
2728
  public:
2729
  // types
2730
- typedef RealType result_type;
2731
- typedef unspecified param_type;
2732
 
2733
  // constructor and reset functions
2734
  explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0);
2735
  explicit extreme_value_distribution(const param_type& parm);
2736
  void reset();
2737
 
2738
  // generating functions
2739
- template<class URNG>
2740
- result_type operator()(URNG& g);
2741
- template<class URNG>
2742
- result_type operator()(URNG& g, const param_type& parm);
2743
 
2744
  // property functions
2745
  RealType a() const;
2746
  RealType b() const;
2747
  param_type param() const;
@@ -2791,27 +2813,26 @@ numbers x distributed according to the probability density function $$%
2791
  \; \mbox{.}$$ The distribution parameters μ and σ are also known as this
2792
  distribution’s *mean* and *standard deviation* .
2793
 
2794
  ``` cpp
2795
  template<class RealType = double>
2796
- class normal_distribution
2797
- {
2798
  public:
2799
  // types
2800
- typedef RealType result_type;
2801
- typedef unspecified param_type;
2802
 
2803
  // constructors and reset functions
2804
  explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
2805
  explicit normal_distribution(const param_type& parm);
2806
  void reset();
2807
 
2808
  // generating functions
2809
- template<class URNG>
2810
- result_type operator()(URNG& g);
2811
- template<class URNG>
2812
- result_type operator()(URNG& g, const param_type& parm);
2813
 
2814
  // property functions
2815
  RealType mean() const;
2816
  RealType stddev() const;
2817
  param_type param() const;
@@ -2859,27 +2880,26 @@ $$%
2859
  }
2860
  \; \mbox{.}$$
2861
 
2862
  ``` cpp
2863
  template<class RealType = double>
2864
- class lognormal_distribution
2865
- {
2866
  public:
2867
  // types
2868
- typedef RealType result_type;
2869
- typedef unspecified param_type;
2870
 
2871
  // constructor and reset functions
2872
  explicit lognormal_distribution(RealType m = 0.0, RealType s = 1.0);
2873
  explicit lognormal_distribution(const param_type& parm);
2874
  void reset();
2875
 
2876
  // generating functions
2877
- template<class URNG>
2878
- result_type operator()(URNG& g);
2879
- template<class URNG>
2880
- result_type operator()(URNG& g, const param_type& parm);
2881
 
2882
  // property functions
2883
  RealType m() const;
2884
  RealType s() const;
2885
  param_type param() const;
@@ -2922,27 +2942,26 @@ $$%
2922
  {\Gamma(n/2) \cdot 2^{n/2}}
2923
  \; \mbox{.}$$
2924
 
2925
  ``` cpp
2926
  template<class RealType = double>
2927
- class chi_squared_distribution
2928
- {
2929
  public:
2930
  // types
2931
- typedef RealType result_type;
2932
- typedef unspecified param_type;
2933
 
2934
  // constructor and reset functions
2935
  explicit chi_squared_distribution(RealType n = 1);
2936
  explicit chi_squared_distribution(const param_type& parm);
2937
  void reset();
2938
 
2939
  // generating functions
2940
- template<class URNG>
2941
- result_type operator()(URNG& g);
2942
- template<class URNG>
2943
- result_type operator()(URNG& g, const param_type& parm);
2944
 
2945
  // property functions
2946
  RealType n() const;
2947
  param_type param() const;
2948
  void param(const param_type& parm);
@@ -2975,27 +2994,26 @@ numbers x distributed according to the probability density function $$%
2975
  = \left( \pi b \left( 1 + \left( \frac{x-a}{b} \right)^2 \;\right)\right)^{-1}
2976
  \; \mbox{.}$$
2977
 
2978
  ``` cpp
2979
  template<class RealType = double>
2980
- class cauchy_distribution
2981
- {
2982
  public:
2983
  // types
2984
- typedef RealType result_type;
2985
- typedef unspecified param_type;
2986
 
2987
  // constructor and reset functions
2988
  explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0);
2989
  explicit cauchy_distribution(const param_type& parm);
2990
  void reset();
2991
 
2992
  // generating functions
2993
- template<class URNG>
2994
- result_type operator()(URNG& g);
2995
- template<class URNG>
2996
- result_type operator()(URNG& g, const param_type& parm);
2997
 
2998
  // property functions
2999
  RealType a() const;
3000
  RealType b() const;
3001
  param_type param() const;
@@ -3044,27 +3062,26 @@ $$%
3044
  {\left( 1 + \frac{m x}{n} \right)}^{-(m+n)/2}
3045
  \; \mbox{.}$$
3046
 
3047
  ``` cpp
3048
  template<class RealType = double>
3049
- class fisher_f_distribution
3050
- {
3051
  public:
3052
  // types
3053
- typedef RealType result_type;
3054
- typedef unspecified param_type;
3055
 
3056
  // constructor and reset functions
3057
  explicit fisher_f_distribution(RealType m = 1, RealType n = 1);
3058
  explicit fisher_f_distribution(const param_type& parm);
3059
  void reset();
3060
 
3061
  // generating functions
3062
- template<class URNG>
3063
- result_type operator()(URNG& g);
3064
- template<class URNG>
3065
- result_type operator()(URNG& g, const param_type& parm);
3066
 
3067
  // property functions
3068
  RealType m() const;
3069
  RealType n() const;
3070
  param_type param() const;
@@ -3109,27 +3126,26 @@ numbers x distributed according to the probability density function $$%
3109
  \cdot \left( 1+\frac{x^2}{n} \right) ^ {-(n+1)/2}
3110
  \; \mbox{.}$$
3111
 
3112
  ``` cpp
3113
  template<class RealType = double>
3114
- class student_t_distribution
3115
- {
3116
  public:
3117
  // types
3118
- typedef RealType result_type;
3119
- typedef unspecified param_type;
3120
 
3121
  // constructor and reset functions
3122
  explicit student_t_distribution(RealType n = 1);
3123
  explicit student_t_distribution(const param_type& parm);
3124
  void reset();
3125
 
3126
  // generating functions
3127
- template<class URNG>
3128
- result_type operator()(URNG& g);
3129
- template<class URNG>
3130
- result_type operator()(URNG& g, const param_type& parm);
3131
 
3132
  // property functions
3133
  RealType n() const;
3134
  param_type param() const;
3135
  void param(const param_type& parm);
@@ -3171,16 +3187,15 @@ the values wₖ, commonly known as the *weights* , shall be non-negative,
3171
  non-NaN, and non-infinity. Moreover, the following relation shall hold:
3172
  0 < S = w₀ + ⋯ + wₙ₋₁.
3173
 
3174
  ``` cpp
3175
  template<class IntType = int>
3176
- class discrete_distribution
3177
- {
3178
  public:
3179
  // types
3180
- typedef IntType result_type;
3181
- typedef unspecified param_type;
3182
 
3183
  // constructor and reset functions
3184
  discrete_distribution();
3185
  template<class InputIterator>
3186
  discrete_distribution(InputIterator firstW, InputIterator lastW);
@@ -3189,14 +3204,14 @@ public:
3189
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
3190
  explicit discrete_distribution(const param_type& parm);
3191
  void reset();
3192
 
3193
  // generating functions
3194
- template<class URNG>
3195
- result_type operator()(URNG& g);
3196
- template<class URNG>
3197
- result_type operator()(URNG& g, const param_type& parm);
3198
 
3199
  // property functions
3200
  vector<double> probabilities() const;
3201
  param_type param() const;
3202
  void param(const param_type& parm);
@@ -3208,19 +3223,22 @@ public:
3208
  ``` cpp
3209
  discrete_distribution();
3210
  ```
3211
 
3212
  *Effects:* Constructs a `discrete_distribution` object with n = 1 and
3213
- p₀ = 1. Such an object will always deliver the value 0.
 
 
 
3214
 
3215
  ``` cpp
3216
  template<class InputIterator>
3217
  discrete_distribution(InputIterator firstW, InputIterator lastW);
3218
  ```
3219
 
3220
  *Requires:* `InputIterator` shall satisfy the requirements of an input
3221
- iterator (Table  [[tab:iterator.input.requirements]]) type. Moreover,
3222
  `iterator_traits<InputIterator>::value_type` shall denote a type that is
3223
  convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
3224
  Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
3225
 
3226
  *Effects:* Constructs a `discrete_distribution` object with
@@ -3281,34 +3299,34 @@ commonly known as the *weights* , shall be non-negative, non-NaN, and
3281
  non-infinity. Moreover, the following relation shall hold:
3282
  0 < S = w₀ + ⋯ + wₙ₋₁.
3283
 
3284
  ``` cpp
3285
  template<class RealType = double>
3286
- class piecewise_constant_distribution
3287
- {
3288
  public:
3289
  // types
3290
- typedef RealType result_type;
3291
- typedef unspecified param_type;
3292
 
3293
  // constructor and reset functions
3294
  piecewise_constant_distribution();
3295
  template<class InputIteratorB, class InputIteratorW>
3296
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
3297
  InputIteratorW firstW);
3298
  template<class UnaryOperation>
3299
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
3300
  template<class UnaryOperation>
3301
- piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
 
3302
  explicit piecewise_constant_distribution(const param_type& parm);
3303
  void reset();
3304
 
3305
  // generating functions
3306
- template<class URNG>
3307
- result_type operator()(URNG& g);
3308
- template<class URNG>
3309
- result_type operator()(URNG& g, const param_type& parm);
3310
 
3311
  // property functions
3312
  vector<result_type> intervals() const;
3313
  vector<result_type> densities() const;
3314
  param_type param() const;
@@ -3421,16 +3439,15 @@ relation shall hold: $$%
3421
  \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
3422
  \; \mbox{.}$$
3423
 
3424
  ``` cpp
3425
  template<class RealType = double>
3426
- class piecewise_linear_distribution
3427
- {
3428
  public:
3429
  // types
3430
- typedef RealType result_type;
3431
- typedef unspecified param_type;
3432
 
3433
  // constructor and reset functions
3434
  piecewise_linear_distribution();
3435
  template<class InputIteratorB, class InputIteratorW>
3436
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
@@ -3441,14 +3458,14 @@ public:
3441
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
3442
  explicit piecewise_linear_distribution(const param_type& parm);
3443
  void reset();
3444
 
3445
  // generating functions
3446
- template<class URNG>
3447
- result_type operator()(URNG& g);
3448
- template<class URNG>
3449
- result_type operator()(URNG& g, const param_type& parm);
3450
 
3451
  // property functions
3452
  vector<result_type> intervals() const;
3453
  vector<result_type> densities() const;
3454
  param_type param() const;
@@ -3534,19 +3551,43 @@ vector<result_type> densities() const;
3534
 
3535
  *Returns:* A `vector<result_type>` whose `size` member returns n and
3536
  whose `operator[]` member returns ρₖ when invoked with argument k for
3537
  k = 0, …, n.
3538
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3539
  ## Numeric arrays <a id="numarray">[[numarray]]</a>
3540
 
3541
  ### Header `<valarray>` synopsis <a id="valarray.syn">[[valarray.syn]]</a>
3542
 
3543
  ``` cpp
3544
  #include <initializer_list>
3545
 
3546
  namespace std {
3547
-
3548
  template<class T> class valarray; // An array of type T
3549
  class slice; // a BLAS-like slice out of an array
3550
  template<class T> class slice_array;
3551
  class gslice; // a generalized slice out of an array
3552
  template<class T> class gslice_array;
@@ -3685,11 +3726,11 @@ additional functions and operators as follows:
3685
  identical functions taking every combination of `const valarray<T>&`
3686
  and replacement types shall be added.
3687
 
3688
  In particular, an implementation shall allow a `valarray<T>` to be
3689
  constructed from such replacement types and shall allow assignments and
3690
- computed assignments of such types to `valarray<T>`, `slice_array<T>`,
3691
  `gslice_array<T>`, `mask_array<T>` and `indirect_array<T>` objects.
3692
 
3693
  These library functions are permitted to throw a `bad_alloc` (
3694
  [[bad.alloc]]) exception if there are not sufficient resources available
3695
  to carry out the operation. Note that the exception is not mandated.
@@ -3700,13 +3741,13 @@ to carry out the operation. Note that the exception is not mandated.
3700
 
3701
  ``` cpp
3702
  namespace std {
3703
  template<class T> class valarray {
3704
  public:
3705
- typedef T value_type;
3706
 
3707
- // [valarray.cons] construct/destroy:
3708
  valarray();
3709
  explicit valarray(size_t);
3710
  valarray(const T&, size_t);
3711
  valarray(const T*, size_t);
3712
  valarray(const valarray&);
@@ -3716,149 +3757,151 @@ namespace std {
3716
  valarray(const mask_array<T>&);
3717
  valarray(const indirect_array<T>&);
3718
  valarray(initializer_list<T>);
3719
  ~valarray();
3720
 
3721
- // [valarray.assign] assignment:
3722
- valarray<T>& operator=(const valarray<T>&);
3723
- valarray<T>& operator=(valarray<T>&&) noexcept;
3724
  valarray& operator=(initializer_list<T>);
3725
- valarray<T>& operator=(const T&);
3726
- valarray<T>& operator=(const slice_array<T>&);
3727
- valarray<T>& operator=(const gslice_array<T>&);
3728
- valarray<T>& operator=(const mask_array<T>&);
3729
- valarray<T>& operator=(const indirect_array<T>&);
3730
 
3731
- // [valarray.access] element access:
3732
  const T& operator[](size_t) const;
3733
  T& operator[](size_t);
3734
 
3735
- // [valarray.sub] subset operations:
3736
- valarray<T> operator[](slice) const;
3737
  slice_array<T> operator[](slice);
3738
- valarray<T> operator[](const gslice&) const;
3739
  gslice_array<T> operator[](const gslice&);
3740
- valarray<T> operator[](const valarray<bool>&) const;
3741
  mask_array<T> operator[](const valarray<bool>&);
3742
- valarray<T> operator[](const valarray<size_t>&) const;
3743
  indirect_array<T> operator[](const valarray<size_t>&);
3744
 
3745
- // [valarray.unary] unary operators:
3746
- valarray<T> operator+() const;
3747
- valarray<T> operator-() const;
3748
- valarray<T> operator~() const;
3749
  valarray<bool> operator!() const;
3750
 
3751
- // [valarray.cassign] computed assignment:
3752
- valarray<T>& operator*= (const T&);
3753
- valarray<T>& operator/= (const T&);
3754
- valarray<T>& operator%= (const T&);
3755
- valarray<T>& operator+= (const T&);
3756
- valarray<T>& operator-= (const T&);
3757
- valarray<T>& operator^= (const T&);
3758
- valarray<T>& operator&= (const T&);
3759
- valarray<T>& operator|= (const T&);
3760
- valarray<T>& operator<<=(const T&);
3761
- valarray<T>& operator>>=(const T&);
3762
 
3763
- valarray<T>& operator*= (const valarray<T>&);
3764
- valarray<T>& operator/= (const valarray<T>&);
3765
- valarray<T>& operator%= (const valarray<T>&);
3766
- valarray<T>& operator+= (const valarray<T>&);
3767
- valarray<T>& operator-= (const valarray<T>&);
3768
- valarray<T>& operator^= (const valarray<T>&);
3769
- valarray<T>& operator|= (const valarray<T>&);
3770
- valarray<T>& operator&= (const valarray<T>&);
3771
- valarray<T>& operator<<=(const valarray<T>&);
3772
- valarray<T>& operator>>=(const valarray<T>&);
3773
 
3774
- // [valarray.members] member functions:
3775
  void swap(valarray&) noexcept;
3776
 
3777
  size_t size() const;
3778
 
3779
  T sum() const;
3780
  T min() const;
3781
  T max() const;
3782
 
3783
- valarray<T> shift (int) const;
3784
- valarray<T> cshift(int) const;
3785
- valarray<T> apply(T func(T)) const;
3786
- valarray<T> apply(T func(const T&)) const;
3787
  void resize(size_t sz, T c = T());
3788
  };
 
 
3789
  }
3790
  ```
3791
 
3792
  The class template `valarray<T>` is a one-dimensional smart array, with
3793
  elements numbered sequentially from zero. It is a representation of the
3794
- mathematical concept of an ordered set of values. The illusion of higher
3795
- dimensionality may be produced by the familiar idiom of computed
3796
- indices, together with the powerful subsetting capabilities provided by
3797
- the generalized subscript operators.[^8]
 
 
3798
 
3799
  An implementation is permitted to qualify any of the functions declared
3800
  in `<valarray>` as `inline`.
3801
 
3802
  #### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
3803
 
3804
  ``` cpp
3805
  valarray();
3806
  ```
3807
 
3808
- *Effects:* Constructs an object of class `valarray<T>`[^9] which has
3809
- zero length.[^10]
3810
 
3811
  ``` cpp
3812
- explicit valarray(size_t);
3813
  ```
3814
 
3815
- The array created by this constructor has a length equal to the value of
3816
- the argument. The elements of the array are
3817
- value-initialized ([[dcl.init]]).
3818
 
3819
  ``` cpp
3820
- valarray(const T&, size_t);
3821
  ```
3822
 
3823
- The array created by this constructor has a length equal to the second
3824
- argument. The elements of the array are initialized with the value of
3825
- the first argument.
3826
 
3827
  ``` cpp
3828
- valarray(const T*, size_t);
3829
  ```
3830
 
3831
- The array created by this constructor has a length equal to the second
3832
- argument `n`. The values of the elements of the array are initialized
3833
- with the first `n` values pointed to by the first argument.[^11] If the
3834
- value of the second argument is greater than the number of values
3835
- pointed to by the first argument, the behavior is undefined.
 
3836
 
3837
  ``` cpp
3838
- valarray(const valarray<T>&);
3839
  ```
3840
 
3841
- The array created by this constructor has the same length as the
3842
- argument array. The elements are initialized with the values of the
3843
- corresponding elements of the argument array.[^12]
3844
 
3845
  ``` cpp
3846
- valarray(valarray<T>&& v) noexcept;
3847
  ```
3848
 
3849
- The array created by this constructor has the same length as the
3850
- argument array. The elements are initialized with the values of the
3851
- corresponding elements of the argument array.
3852
 
3853
  *Complexity:* Constant.
3854
 
3855
  ``` cpp
3856
  valarray(initializer_list<T> il);
3857
  ```
3858
 
3859
- *Effects:* Same as `valarray(il.begin(), il.size())`.
3860
 
3861
  ``` cpp
3862
  valarray(const slice_array<T>&);
3863
  valarray(const gslice_array<T>&);
3864
  valarray(const mask_array<T>&);
@@ -3870,101 +3913,103 @@ templates to a `valarray`.
3870
 
3871
  ``` cpp
3872
  ~valarray();
3873
  ```
3874
 
3875
- The destructor is applied to every element of `*this`; an implementation
3876
- may return all allocated memory.
3877
 
3878
  #### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
3879
 
3880
  ``` cpp
3881
- valarray<T>& operator=(const valarray<T>& v);
3882
  ```
3883
 
3884
- Each element of the `*this` array is assigned the value of the
3885
- corresponding element of the argument array. If the length of `v` is not
3886
- equal to the length of `*this` , resizes `*this` to make the two arrays
3887
- the same length, as if by calling `resize(v.size())`, before performing
3888
- the assignment.
3889
 
3890
- `size() == v.size()`.
 
 
3891
 
3892
  ``` cpp
3893
- valarray<T>& operator=(valarray<T>&& v) noexcept;
3894
  ```
3895
 
3896
  *Effects:* `*this` obtains the value of `v`. The value of `v` after the
3897
  assignment is not specified.
3898
 
 
 
3899
  *Complexity:* Linear.
3900
 
3901
  ``` cpp
3902
  valarray& operator=(initializer_list<T> il);
3903
  ```
3904
 
3905
- *Effects:* `*this = valarray(il)`.
3906
-
3907
- *Returns:* `*this`.
3908
 
3909
  ``` cpp
3910
- valarray<T>& operator=(const T&);
3911
  ```
3912
 
3913
- The scalar assignment operator causes each element of the `*this` array
3914
- to be assigned the value of the argument.
 
3915
 
3916
  ``` cpp
3917
- valarray<T>& operator=(const slice_array<T>&);
3918
- valarray<T>& operator=(const gslice_array<T>&);
3919
- valarray<T>& operator=(const mask_array<T>&);
3920
- valarray<T>& operator=(const indirect_array<T>&);
3921
  ```
3922
 
3923
  *Requires:* The length of the array to which the argument refers equals
3924
- `size()`.
 
 
3925
 
3926
  These operators allow the results of a generalized subscripting
3927
  operation to be assigned directly to a `valarray`.
3928
 
3929
- If the value of an element in the left-hand side of a valarray
3930
- assignment operator depends on the value of another element in that
3931
- left-hand side, the resulting behavior is undefined.
3932
-
3933
  #### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
3934
 
3935
  ``` cpp
3936
- const T& operator[](size_t) const;
3937
- T& operator[](size_t);
3938
  ```
3939
 
3940
- The subscript operator returns a reference to the corresponding element
3941
- of the array.
3942
 
3943
- Thus, the expression `(a[i] = q, a[i]) == q` evaluates as true for any
3944
- non-constant `valarray<T> a`, any `T q`, and for any `size_t i` such
3945
- that the value of `i` is less than the length of `a`.
3946
 
3947
- The expression `&a[i+j] == &a[i] + j` evaluates as true for all
3948
- `size_t i` and `size_t j` such that `i+j` is less than the length of the
3949
- array `a`.
 
3950
 
3951
- Likewise, the expression `&a[i] != &b[j]` evaluates as `true` for any
3952
- two arrays `a` and `b` and for any `size_t i` and `size_t j` such that
3953
- `i` is less than the length of `a` and `j` is less than the length of
3954
- `b`. This property indicates an absence of aliasing and may be used to
3955
- advantage by optimizing compilers.[^13]
 
 
 
 
 
 
 
3956
 
3957
  The reference returned by the subscript operator for an array shall be
3958
  valid until the member function
3959
  `resize(size_t, T)` ([[valarray.members]]) is called for that array or
3960
  until the lifetime of that array ends, whichever happens first.
3961
 
3962
- If the subscript operator is invoked with a `size_t` argument whose
3963
- value is not less than the length of the array, the behavior is
3964
- undefined.
3965
-
3966
  #### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
3967
 
3968
  The member `operator[]` is overloaded to provide several ways to select
3969
  sequences of elements from among those controlled by `*this`. Each of
3970
  these operations returns a subset of the array. The const-qualified
@@ -3974,200 +4019,231 @@ the original array, working in conjunction with various overloads of
3974
  `operator=` and other assigning operators to allow selective replacement
3975
  (slicing) of the controlled sequence. In each case the selected
3976
  element(s) must exist.
3977
 
3978
  ``` cpp
3979
- valarray<T> operator[](slice slicearr) const;
3980
  ```
3981
 
3982
- *Returns:* An object of class `valarray<T>` containing those elements of
3983
- the controlled sequence designated by `slicearr`.
 
 
3984
 
3985
  ``` cpp
3986
  const valarray<char> v0("abcdefghijklmnop", 16);
3987
  // v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
3988
  ```
3989
 
 
 
3990
  ``` cpp
3991
  slice_array<T> operator[](slice slicearr);
3992
  ```
3993
 
3994
  *Returns:* An object that holds references to elements of the controlled
3995
  sequence selected by `slicearr`.
3996
 
 
 
3997
  ``` cpp
3998
  valarray<char> v0("abcdefghijklmnop", 16);
3999
  valarray<char> v1("ABCDE", 5);
4000
  v0[slice(2, 5, 3)] = v1;
4001
  // v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
4002
  ```
4003
 
 
 
4004
  ``` cpp
4005
- valarray<T> operator[](const gslice& gslicearr) const;
4006
  ```
4007
 
4008
- *Returns:* An object of class `valarray<T>` containing those elements of
4009
- the controlled sequence designated by `gslicearr`.
 
 
4010
 
4011
  ``` cpp
4012
  const valarray<char> v0("abcdefghijklmnop", 16);
4013
  const size_t lv[] = { 2, 3 };
4014
  const size_t dv[] = { 7, 2 };
4015
  const valarray<size_t> len(lv, 2), str(dv, 2);
4016
  // v0[gslice(3, len, str)] returns
4017
  // valarray<char>("dfhkmo", 6)
4018
  ```
4019
 
 
 
4020
  ``` cpp
4021
  gslice_array<T> operator[](const gslice& gslicearr);
4022
  ```
4023
 
4024
  *Returns:* An object that holds references to elements of the controlled
4025
  sequence selected by `gslicearr`.
4026
 
 
 
4027
  ``` cpp
4028
  valarray<char> v0("abcdefghijklmnop", 16);
4029
- valarray<char> v1("ABCDE", 5);
4030
  const size_t lv[] = { 2, 3 };
4031
  const size_t dv[] = { 7, 2 };
4032
  const valarray<size_t> len(lv, 2), str(dv, 2);
4033
  v0[gslice(3, len, str)] = v1;
4034
  // v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
4035
  ```
4036
 
 
 
4037
  ``` cpp
4038
- valarray<T> operator[](const valarray<bool>& boolarr) const;
4039
  ```
4040
 
4041
- *Returns:* An object of class `valarray<T>` containing those elements of
4042
- the controlled sequence designated by `boolarr`.
 
 
4043
 
4044
  ``` cpp
4045
  const valarray<char> v0("abcdefghijklmnop", 16);
4046
  const bool vb[] = { false, false, true, true, false, true };
4047
  // v0[valarray<bool>(vb, 6)] returns
4048
  // valarray<char>("cdf", 3)
4049
  ```
4050
 
 
 
4051
  ``` cpp
4052
  mask_array<T> operator[](const valarray<bool>& boolarr);
4053
  ```
4054
 
4055
  *Returns:* An object that holds references to elements of the controlled
4056
  sequence selected by `boolarr`.
4057
 
 
 
4058
  ``` cpp
4059
  valarray<char> v0("abcdefghijklmnop", 16);
4060
  valarray<char> v1("ABC", 3);
4061
  const bool vb[] = { false, false, true, true, false, true };
4062
  v0[valarray<bool>(vb, 6)] = v1;
4063
  // v0 == valarray<char>("abABeCghijklmnop", 16)
4064
  ```
4065
 
 
 
4066
  ``` cpp
4067
- valarray<T> operator[](const valarray<size_t>& indarr) const;
4068
  ```
4069
 
4070
- *Returns:* An object of class `valarray<T>` containing those elements of
4071
- the controlled sequence designated by `indarr`.
 
 
4072
 
4073
  ``` cpp
4074
  const valarray<char> v0("abcdefghijklmnop", 16);
4075
  const size_t vi[] = { 7, 5, 2, 3, 8 };
4076
  // v0[valarray<size_t>(vi, 5)] returns
4077
  // valarray<char>("hfcdi", 5)
4078
  ```
4079
 
 
 
4080
  ``` cpp
4081
  indirect_array<T> operator[](const valarray<size_t>& indarr);
4082
  ```
4083
 
4084
  *Returns:* An object that holds references to elements of the controlled
4085
  sequence selected by `indarr`.
4086
 
 
 
4087
  ``` cpp
4088
  valarray<char> v0("abcdefghijklmnop", 16);
4089
  valarray<char> v1("ABCDE", 5);
4090
  const size_t vi[] = { 7, 5, 2, 3, 8 };
4091
  v0[valarray<size_t>(vi, 5)] = v1;
4092
  // v0 == valarray<char>("abCDeBgAEjklmnop", 16)
4093
  ```
4094
 
 
 
4095
  #### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
4096
 
4097
  ``` cpp
4098
- valarray<T> operator+() const;
4099
- valarray<T> operator-() const;
4100
- valarray<T> operator~() const;
4101
  valarray<bool> operator!() const;
4102
  ```
4103
 
4104
- Each of these operators may only be instantiated for a type `T` to which
4105
- the indicated operator can be applied and for which the indicated
4106
- operator returns a value which is of type `T` (`bool` for `operator!`)
4107
- or which may be unambiguously implicitly converted to type `T` (`bool`
4108
- for `operator!`).
4109
 
4110
- Each of these operators returns an array whose length is equal to the
4111
- length of the array. Each element of the returned array is initialized
4112
- with the result of applying the indicated operator to the corresponding
4113
- element of the array.
4114
 
4115
- #### `valarray` computed assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
4116
 
4117
  ``` cpp
4118
- valarray<T>& operator*= (const valarray<T>&);
4119
- valarray<T>& operator/= (const valarray<T>&);
4120
- valarray<T>& operator%= (const valarray<T>&);
4121
- valarray<T>& operator+= (const valarray<T>&);
4122
- valarray<T>& operator-= (const valarray<T>&);
4123
- valarray<T>& operator^= (const valarray<T>&);
4124
- valarray<T>& operator&= (const valarray<T>&);
4125
- valarray<T>& operator|= (const valarray<T>&);
4126
- valarray<T>& operator<<=(const valarray<T>&);
4127
- valarray<T>& operator>>=(const valarray<T>&);
4128
  ```
4129
 
4130
- Each of these operators may only be instantiated for a type `T` to which
4131
- the indicated operator can be applied. Each of these operators performs
4132
- the indicated operation on each of its elements and the corresponding
4133
- element of the argument array.
 
4134
 
4135
- The array is then returned by reference.
 
4136
 
4137
- If the array and the argument array do not have the same length, the
4138
- behavior is undefined. The appearance of an array on the left-hand side
4139
- of a computed assignment does `not` invalidate references or pointers.
4140
 
4141
- If the value of an element in the left-hand side of a valarray computed
4142
- assignment operator depends on the value of another element in that left
4143
- hand side, the resulting behavior is undefined.
4144
 
4145
  ``` cpp
4146
- valarray<T>& operator*= (const T&);
4147
- valarray<T>& operator/= (const T&);
4148
- valarray<T>& operator%= (const T&);
4149
- valarray<T>& operator+= (const T&);
4150
- valarray<T>& operator-= (const T&);
4151
- valarray<T>& operator^= (const T&);
4152
- valarray<T>& operator&= (const T&);
4153
- valarray<T>& operator|= (const T&);
4154
- valarray<T>& operator<<=(const T&);
4155
- valarray<T>& operator>>=(const T&);
4156
  ```
4157
 
4158
- Each of these operators may only be instantiated for a type `T` to which
4159
- the indicated operator can be applied.
 
4160
 
4161
- Each of these operators applies the indicated operation to each element
4162
- of the array and the non-array argument.
4163
 
4164
- The array is then returned by reference.
4165
 
4166
- The appearance of an array on the left-hand side of a computed
4167
- assignment does *not* invalidate references or pointers to the elements
4168
- of the array.
4169
 
4170
  #### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
4171
 
4172
  ``` cpp
4173
  void swap(valarray& v) noexcept;
@@ -4188,55 +4264,81 @@ size_t size() const;
4188
 
4189
  ``` cpp
4190
  T sum() const;
4191
  ```
4192
 
4193
- This function may only be instantiated for a type `T` to which
4194
- `operator+=` can be applied. This function returns the sum of all the
4195
- elements of the array.
4196
 
4197
- If the array has length 0, the behavior is undefined. If the array has
4198
- length 1, `sum()` returns the value of element 0. Otherwise, the
4199
- returned value is calculated by applying `operator+=` to a copy of an
4200
- element of the array and all other elements of the array in an
4201
- unspecified order.
4202
 
4203
  ``` cpp
4204
  T min() const;
4205
  ```
4206
 
4207
- This function returns the minimum value contained in `*this`. The value
4208
- returned for an array of length 0 is undefined. For an array of length
4209
- 1, the value of element 0 is returned. For all other array lengths, the
4210
- determination is made using `operator<`.
 
4211
 
4212
  ``` cpp
4213
  T max() const;
4214
  ```
4215
 
4216
- This function returns the maximum value contained in `*this`. The value
4217
- returned for an array of length 0 is undefined. For an array of length
4218
- 1, the value of element 0 is returned. For all other array lengths, the
4219
- determination is made using `operator<`.
 
4220
 
4221
  ``` cpp
4222
- valarray<T> shift(int n) const;
4223
  ```
4224
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4225
  ``` cpp
4226
- valarray<T> cshift(int n) const;
4227
  ```
4228
 
 
 
 
 
 
4229
  ``` cpp
4230
- valarray<T> apply(T func(T)) const;
4231
- valarray<T> apply(T func(const T&)) const;
4232
  ```
4233
 
 
 
 
 
4234
  ``` cpp
4235
  void resize(size_t sz, T c = T());
4236
  ```
4237
 
 
 
 
 
4238
  ### `valarray` non-member operations <a id="valarray.nonmembers">[[valarray.nonmembers]]</a>
4239
 
4240
  #### `valarray` binary operators <a id="valarray.binary">[[valarray.binary]]</a>
4241
 
4242
  ``` cpp
@@ -4260,22 +4362,20 @@ template<class T> valarray<T> operator<<
4260
  (const valarray<T>&, const valarray<T>&);
4261
  template<class T> valarray<T> operator>>
4262
  (const valarray<T>&, const valarray<T>&);
4263
  ```
4264
 
4265
- Each of these operators may only be instantiated for a type `T` to which
4266
- the indicated operator can be applied and for which the indicated
4267
- operator returns a value which is of type `T` or which can be
4268
- unambiguously implicitly converted to type `T`.
 
4269
 
4270
- Each of these operators returns an array whose length is equal to the
4271
- lengths of the argument arrays. Each element of the returned array is
4272
- initialized with the result of applying the indicated operator to the
4273
- corresponding elements of the argument arrays.
4274
-
4275
- If the argument arrays do not have the same length, the behavior is
4276
- undefined.
4277
 
4278
  ``` cpp
4279
  template<class T> valarray<T> operator* (const valarray<T>&, const T&);
4280
  template<class T> valarray<T> operator* (const T&, const valarray<T>&);
4281
  template<class T> valarray<T> operator/ (const valarray<T>&, const T&);
@@ -4296,19 +4396,19 @@ template<class T> valarray<T> operator<<(const valarray<T>&, const T&);
4296
  template<class T> valarray<T> operator<<(const T&, const valarray<T>&);
4297
  template<class T> valarray<T> operator>>(const valarray<T>&, const T&);
4298
  template<class T> valarray<T> operator>>(const T&, const valarray<T>&);
4299
  ```
4300
 
4301
- Each of these operators may only be instantiated for a type `T` to which
4302
- the indicated operator can be applied and for which the indicated
4303
- operator returns a value which is of type `T` or which can be
4304
  unambiguously implicitly converted to type `T`.
4305
 
4306
- Each of these operators returns an array whose length is equal to the
4307
- length of the array argument. Each element of the returned array is
4308
- initialized with the result of applying the indicated operator to the
4309
- corresponding element of the array argument and the non-array argument.
4310
 
4311
  #### `valarray` logical operators <a id="valarray.comparison">[[valarray.comparison]]</a>
4312
 
4313
  ``` cpp
4314
  template<class T> valarray<bool> operator==
@@ -4327,22 +4427,20 @@ template<class T> valarray<bool> operator&&
4327
  (const valarray<T>&, const valarray<T>&);
4328
  template<class T> valarray<bool> operator||
4329
  (const valarray<T>&, const valarray<T>&);
4330
  ```
4331
 
4332
- Each of these operators may only be instantiated for a type `T` to which
4333
- the indicated operator can be applied and for which the indicated
4334
- operator returns a value which is of type `bool` or which can be
4335
- unambiguously implicitly converted to type `bool`.
 
4336
 
4337
- Each of these operators returns a `bool` array whose length is equal to
4338
- the length of the array arguments. Each element of the returned array is
4339
- initialized with the result of applying the indicated operator to the
4340
- corresponding elements of the argument arrays.
4341
-
4342
- If the two array arguments do not have the same length, the behavior is
4343
- undefined.
4344
 
4345
  ``` cpp
4346
  template<class T> valarray<bool> operator==(const valarray<T>&, const T&);
4347
  template<class T> valarray<bool> operator==(const T&, const valarray<T>&);
4348
  template<class T> valarray<bool> operator!=(const valarray<T>&, const T&);
@@ -4359,19 +4457,19 @@ template<class T> valarray<bool> operator&&(const valarray<T>&, const T&);
4359
  template<class T> valarray<bool> operator&&(const T&, const valarray<T>&);
4360
  template<class T> valarray<bool> operator||(const valarray<T>&, const T&);
4361
  template<class T> valarray<bool> operator||(const T&, const valarray<T>&);
4362
  ```
4363
 
4364
- Each of these operators may only be instantiated for a type `T` to which
4365
- the indicated operator can be applied and for which the indicated
4366
- operator returns a value which is of type `bool` or which can be
4367
- unambiguously implicitly converted to type `bool`.
4368
 
4369
- Each of these operators returns a `bool` array whose length is equal to
4370
- the length of the array argument. Each element of the returned array is
4371
- initialized with the result of applying the indicated operator to the
4372
- corresponding element of the array and the non-array argument.
4373
 
4374
  #### `valarray` transcendentals <a id="valarray.transcend">[[valarray.transcend]]</a>
4375
 
4376
  ``` cpp
4377
  template<class T> valarray<T> abs (const valarray<T>&);
@@ -4396,22 +4494,22 @@ template<class T> valarray<T> sinh (const valarray<T>&);
4396
  template<class T> valarray<T> sqrt (const valarray<T>&);
4397
  template<class T> valarray<T> tan (const valarray<T>&);
4398
  template<class T> valarray<T> tanh (const valarray<T>&);
4399
  ```
4400
 
4401
- Each of these functions may only be instantiated for a type `T` to which
4402
- a unique function with the indicated name can be applied (unqualified).
4403
- This function shall return a value which is of type `T` or which can be
4404
- unambiguously implicitly converted to type `T`.
4405
 
4406
  #### `valarray` specialized algorithms <a id="valarray.special">[[valarray.special]]</a>
4407
 
4408
  ``` cpp
4409
  template <class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
4410
  ```
4411
 
4412
- *Effects:* `x.swap(y)`.
4413
 
4414
  ### Class `slice` <a id="class.slice">[[class.slice]]</a>
4415
 
4416
  #### Class `slice` overview <a id="class.slice.overview">[[class.slice.overview]]</a>
4417
 
@@ -4428,11 +4526,11 @@ namespace std {
4428
  };
4429
  }
4430
  ```
4431
 
4432
  The `slice` class represents a BLAS-like slice from an array. Such a
4433
- slice is specified by a starting index, a length, and a stride.[^14]
4434
 
4435
  #### `slice` constructors <a id="cons.slice">[[cons.slice]]</a>
4436
 
4437
  ``` cpp
4438
  slice();
@@ -4443,12 +4541,12 @@ slice(const slice&);
4443
  The default constructor is equivalent to `slice(0, 0, 0)`. A default
4444
  constructor is provided only to permit the declaration of arrays of
4445
  slices. The constructor with arguments for a slice takes a start,
4446
  length, and stride parameter.
4447
 
4448
- `slice(3, 8, 2)` constructs a slice which selects elements 3, 5, 7, ...
4449
- 17 from an array.
4450
 
4451
  #### `slice` access functions <a id="slice.access">[[slice.access]]</a>
4452
 
4453
  ``` cpp
4454
  size_t start() const;
@@ -4466,11 +4564,11 @@ size_t stride() const;
4466
 
4467
  ``` cpp
4468
  namespace std {
4469
  template <class T> class slice_array {
4470
  public:
4471
- typedef T value_type;
4472
 
4473
  void operator= (const valarray<T>&) const;
4474
  void operator*= (const valarray<T>&) const;
4475
  void operator/= (const valarray<T>&) const;
4476
  void operator%= (const valarray<T>&) const;
@@ -4500,13 +4598,14 @@ slice_array<T> valarray<T>::operator[](slice);
4500
  ```
4501
 
4502
  It has reference semantics to a subset of an array specified by a
4503
  `slice` object.
4504
 
4505
- The expression `a[slice(1, 5, 3)] = b;` has the effect of assigning the
4506
- elements of `b` to a slice of the elements in `a`. For the slice shown,
4507
- the elements selected from `a` are 1, 4, ..., 13.
 
4508
 
4509
  #### `slice_array` assignment <a id="slice.arr.assign">[[slice.arr.assign]]</a>
4510
 
4511
  ``` cpp
4512
  void operator=(const valarray<T>&) const;
@@ -4515,11 +4614,11 @@ const slice_array& operator=(const slice_array&) const;
4515
 
4516
  These assignment operators have reference semantics, assigning the
4517
  values of the argument array elements to selected elements of the
4518
  `valarray<T>` object to which the `slice_array` object refers.
4519
 
4520
- #### `slice_array` computed assignment <a id="slice.arr.comp.assign">[[slice.arr.comp.assign]]</a>
4521
 
4522
  ``` cpp
4523
  void operator*= (const valarray<T>&) const;
4524
  void operator/= (const valarray<T>&) const;
4525
  void operator%= (const valarray<T>&) const;
@@ -4530,11 +4629,11 @@ void operator&= (const valarray<T>&) const;
4530
  void operator|= (const valarray<T>&) const;
4531
  void operator<<=(const valarray<T>&) const;
4532
  void operator>>=(const valarray<T>&) const;
4533
  ```
4534
 
4535
- These computed assignments have reference semantics, applying the
4536
  indicated operation to the elements of the argument array and selected
4537
  elements of the `valarray<T>` object to which the `slice_array` object
4538
  refers.
4539
 
4540
  #### `slice_array` fill function <a id="slice.arr.fill">[[slice.arr.fill]]</a>
@@ -4574,34 +4673,40 @@ number to the number of strides, to a single index k. It is useful for
4574
  building multidimensional array classes using the `valarray` template,
4575
  which is one-dimensional. The set of one-dimensional index values
4576
  specified by a `gslice` are $$k = s + \sum_j i_j d_j$$ where the
4577
  multidimensional indices iⱼ range in value from 0 to lᵢⱼ - 1.
4578
 
 
 
4579
  The `gslice` specification
4580
 
4581
  ``` cpp
4582
  start = 3
4583
  length = {2, 4, 3}
4584
  stride = {19, 4, 1}
4585
  ```
4586
 
4587
  yields the sequence of one-dimensional indices
4588
-
4589
  $$k = 3 + (0, 1) \times 19 + (0, 1, 2, 3) \times 4 + (0, 1, 2) \times 1$$
4590
-
4591
  which are ordered as shown in the following table:
4592
 
4593
  That is, the highest-ordered index turns fastest.
4594
 
 
 
4595
  It is possible to have degenerate generalized slices in which an address
4596
  is repeated.
4597
 
 
 
4598
  If the stride parameters in the previous example are changed to {1, 1,
4599
  1}, the first few elements of the resulting sequence of indices will be
4600
 
 
 
4601
  If a degenerate slice is used as the argument to the non-`const` version
4602
- of `operator[](const gslice&)`, the resulting behavior is undefined.
4603
 
4604
  #### `gslice` constructors <a id="gslice.cons">[[gslice.cons]]</a>
4605
 
4606
  ``` cpp
4607
  gslice();
@@ -4635,11 +4740,11 @@ linear in the number of strides.
4635
 
4636
  ``` cpp
4637
  namespace std {
4638
  template <class T> class gslice_array {
4639
  public:
4640
- typedef T value_type;
4641
 
4642
  void operator= (const valarray<T>&) const;
4643
  void operator*= (const valarray<T>&) const;
4644
  void operator/= (const valarray<T>&) const;
4645
  void operator%= (const valarray<T>&) const;
@@ -4684,11 +4789,11 @@ const gslice_array& operator=(const gslice_array&) const;
4684
 
4685
  These assignment operators have reference semantics, assigning the
4686
  values of the argument array elements to selected elements of the
4687
  `valarray<T>` object to which the `gslice_array` refers.
4688
 
4689
- #### `gslice_array` <a id="gslice.array.comp.assign">[[gslice.array.comp.assign]]</a>
4690
 
4691
  ``` cpp
4692
  void operator*= (const valarray<T>&) const;
4693
  void operator/= (const valarray<T>&) const;
4694
  void operator%= (const valarray<T>&) const;
@@ -4699,11 +4804,11 @@ void operator&= (const valarray<T>&) const;
4699
  void operator|= (const valarray<T>&) const;
4700
  void operator<<=(const valarray<T>&) const;
4701
  void operator>>=(const valarray<T>&) const;
4702
  ```
4703
 
4704
- These computed assignments have reference semantics, applying the
4705
  indicated operation to the elements of the argument array and selected
4706
  elements of the `valarray<T>` object to which the `gslice_array` object
4707
  refers.
4708
 
4709
  #### `gslice_array` fill function <a id="gslice.array.fill">[[gslice.array.fill]]</a>
@@ -4722,11 +4827,11 @@ argument to the elements of the `valarray<T>` object to which the
4722
 
4723
  ``` cpp
4724
  namespace std {
4725
  template <class T> class mask_array {
4726
  public:
4727
- typedef T value_type;
4728
 
4729
  void operator= (const valarray<T>&) const;
4730
  void operator*= (const valarray<T>&) const;
4731
  void operator/= (const valarray<T>&) const;
4732
  void operator%= (const valarray<T>&) const;
@@ -4768,11 +4873,11 @@ const mask_array& operator=(const mask_array&) const;
4768
 
4769
  These assignment operators have reference semantics, assigning the
4770
  values of the argument array elements to selected elements of the
4771
  `valarray<T>` object to which it refers.
4772
 
4773
- #### `mask_array` computed assignment <a id="mask.array.comp.assign">[[mask.array.comp.assign]]</a>
4774
 
4775
  ``` cpp
4776
  void operator*= (const valarray<T>&) const;
4777
  void operator/= (const valarray<T>&) const;
4778
  void operator%= (const valarray<T>&) const;
@@ -4783,11 +4888,11 @@ void operator&= (const valarray<T>&) const;
4783
  void operator|= (const valarray<T>&) const;
4784
  void operator<<=(const valarray<T>&) const;
4785
  void operator>>=(const valarray<T>&) const;
4786
  ```
4787
 
4788
- These computed assignments have reference semantics, applying the
4789
  indicated operation to the elements of the argument array and selected
4790
  elements of the `valarray<T>` object to which the mask object refers.
4791
 
4792
  #### `mask_array` fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
4793
 
@@ -4805,11 +4910,11 @@ argument to the elements of the `valarray<T>` object to which the
4805
 
4806
  ``` cpp
4807
  namespace std {
4808
  template <class T> class indirect_array {
4809
  public:
4810
- typedef T value_type;
4811
 
4812
  void operator= (const valarray<T>&) const;
4813
  void operator*= (const valarray<T>&) const;
4814
  void operator/= (const valarray<T>&) const;
4815
  void operator%= (const valarray<T>&) const;
@@ -4855,21 +4960,25 @@ values of the argument array elements to selected elements of the
4855
  `valarray<T>` object to which it refers.
4856
 
4857
  If the `indirect_array` specifies an element in the `valarray<T>` object
4858
  to which it refers more than once, the behavior is undefined.
4859
 
 
 
4860
  ``` cpp
4861
  int addr[] = {2, 3, 1, 4, 4};
4862
  valarray<size_t> indirect(addr, 5);
4863
  valarray<double> a(0., 10), b(1., 5);
4864
  a[indirect] = b;
4865
  ```
4866
 
4867
  results in undefined behavior since element 4 is specified twice in the
4868
  indirection.
4869
 
4870
- #### `indirect_array` computed assignment <a id="indirect.array.comp.assign">[[indirect.array.comp.assign]]</a>
 
 
4871
 
4872
  ``` cpp
4873
  void operator*= (const valarray<T>&) const;
4874
  void operator/= (const valarray<T>&) const;
4875
  void operator%= (const valarray<T>&) const;
@@ -4880,11 +4989,11 @@ void operator&= (const valarray<T>&) const;
4880
  void operator|= (const valarray<T>&) const;
4881
  void operator<<=(const valarray<T>&) const;
4882
  void operator>>=(const valarray<T>&) const;
4883
  ```
4884
 
4885
- These computed assignments have reference semantics, applying the
4886
  indicated operation to the elements of the argument array and selected
4887
  elements of the `valarray<T>` object to which the `indirect_array`
4888
  object refers.
4889
 
4890
  If the `indirect_array` specifies an element in the `valarray<T>` object
@@ -4898,19 +5007,21 @@ void operator=(const T&) const;
4898
 
4899
  This function has reference semantics, assigning the value of its
4900
  argument to the elements of the `valarray<T>` object to which the
4901
  `indirect_array` object refers.
4902
 
4903
- ### valarray range access <a id="valarray.range">[[valarray.range]]</a>
4904
 
4905
  In the `begin` and `end` function templates that follow, *unspecified*1
4906
  is a type that meets the requirements of a mutable random access
4907
- iterator ([[random.access.iterators]]) whose `value_type` is the
4908
- template parameter `T` and whose `reference` type is `T&`.
4909
- *unspecified*2 is a type that meets the requirements of a constant
4910
- random access iterator ([[random.access.iterators]]) whose `value_type`
4911
- is the template parameter `T` and whose `reference` type is `const T&`.
 
 
4912
 
4913
  The iterators returned by `begin` and `end` for an array are guaranteed
4914
  to be valid until the member function `resize(size_t, T)` (
4915
  [[valarray.members]]) is called for that array or until the lifetime of
4916
  that array ends, whichever happens first.
@@ -4918,93 +5029,365 @@ that array ends, whichever happens first.
4918
  ``` cpp
4919
  template <class T> unspecified{1} begin(valarray<T>& v);
4920
  template <class T> unspecified{2} begin(const valarray<T>& v);
4921
  ```
4922
 
4923
- *Returns:* An iterator referencing the first value in the numeric array.
4924
 
4925
  ``` cpp
4926
  template <class T> unspecified{1} end(valarray<T>& v);
4927
  template <class T> unspecified{2} end(const valarray<T>& v);
4928
  ```
4929
 
4930
- *Returns:* An iterator referencing one past the last value in the
4931
- numeric array.
4932
 
4933
  ## Generalized numeric operations <a id="numeric.ops">[[numeric.ops]]</a>
4934
 
4935
  ### Header `<numeric>` synopsis <a id="numeric.ops.overview">[[numeric.ops.overview]]</a>
4936
 
4937
  ``` cpp
4938
  namespace std {
 
4939
  template <class InputIterator, class T>
4940
  T accumulate(InputIterator first, InputIterator last, T init);
4941
  template <class InputIterator, class T, class BinaryOperation>
4942
  T accumulate(InputIterator first, InputIterator last, T init,
4943
  BinaryOperation binary_op);
4944
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4945
  template <class InputIterator1, class InputIterator2, class T>
4946
  T inner_product(InputIterator1 first1, InputIterator1 last1,
4947
  InputIterator2 first2, T init);
4948
  template <class InputIterator1, class InputIterator2, class T,
4949
  class BinaryOperation1, class BinaryOperation2>
4950
  T inner_product(InputIterator1 first1, InputIterator1 last1,
4951
  InputIterator2 first2, T init,
4952
  BinaryOperation1 binary_op1,
4953
  BinaryOperation2 binary_op2);
4954
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4955
  template <class InputIterator, class OutputIterator>
4956
  OutputIterator partial_sum(InputIterator first,
4957
  InputIterator last,
4958
  OutputIterator result);
4959
- template <class InputIterator, class OutputIterator,
4960
- class BinaryOperation>
4961
  OutputIterator partial_sum(InputIterator first,
4962
  InputIterator last,
4963
  OutputIterator result,
4964
  BinaryOperation binary_op);
4965
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4966
  template <class InputIterator, class OutputIterator>
4967
  OutputIterator adjacent_difference(InputIterator first,
4968
  InputIterator last,
4969
  OutputIterator result);
4970
- template <class InputIterator, class OutputIterator,
4971
- class BinaryOperation>
4972
  OutputIterator adjacent_difference(InputIterator first,
4973
  InputIterator last,
4974
  OutputIterator result,
4975
  BinaryOperation binary_op);
 
 
 
 
 
 
 
 
 
 
 
 
4976
 
 
4977
  template <class ForwardIterator, class T>
4978
  void iota(ForwardIterator first, ForwardIterator last, T value);
 
 
 
 
 
 
 
 
4979
  }
4980
  ```
4981
 
4982
  The requirements on the types of algorithms’ arguments that are
4983
  described in the introduction to Clause  [[algorithms]] also apply to
4984
  the following algorithms.
4985
 
 
 
 
 
 
 
 
 
4986
  ### Accumulate <a id="accumulate">[[accumulate]]</a>
4987
 
4988
  ``` cpp
4989
  template <class InputIterator, class T>
4990
  T accumulate(InputIterator first, InputIterator last, T init);
4991
  template <class InputIterator, class T, class BinaryOperation>
4992
  T accumulate(InputIterator first, InputIterator last, T init,
4993
  BinaryOperation binary_op);
4994
  ```
4995
 
 
 
 
 
 
 
4996
  *Effects:* Computes its result by initializing the accumulator `acc`
4997
  with the initial value `init` and then modifies it with `acc = acc + *i`
4998
  or `acc = binary_op(acc, *i)` for every iterator `i` in the range
4999
- \[`first`, `last`) in order.[^15]
5000
 
5001
- *Requires:* `T` shall meet the requirements of `CopyConstructible`
5002
- (Table  [[copyconstructible]]) and `CopyAssignable`
5003
- (Table  [[copyassignable]]) types. In the range \[`first`, `last`\],
5004
- `binary_op` shall neither modify elements nor invalidate iterators or
5005
- subranges.[^16]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5006
 
5007
  ### Inner product <a id="inner.product">[[inner.product]]</a>
5008
 
5009
  ``` cpp
5010
  template <class InputIterator1, class InputIterator2, class T>
@@ -5016,98 +5399,532 @@ template <class InputIterator1, class InputIterator2, class T,
5016
  InputIterator2 first2, T init,
5017
  BinaryOperation1 binary_op1,
5018
  BinaryOperation2 binary_op2);
5019
  ```
5020
 
 
 
 
 
 
 
 
5021
  *Effects:* Computes its result by initializing the accumulator `acc`
5022
  with the initial value `init` and then modifying it with
5023
  `acc = acc + (*i1) * (*i2)` or
5024
  `acc = binary_op1(acc, binary_op2(*i1, *i2))` for every iterator `i1` in
5025
  the range \[`first1`, `last1`) and iterator `i2` in the range
5026
  \[`first2`, `first2 + (last1 - first1)`) in order.
5027
 
5028
- *Requires:* `T` shall meet the requirements of `CopyConstructible`
5029
- (Table  [[copyconstructible]]) and `CopyAssignable`
5030
- (Table  [[copyassignable]]) types. In the ranges \[`first1`, `last1`\]
5031
- and \[`first2`, `first2 + (last1 - first1)`\] `binary_op1` and
5032
- `binary_op2` shall neither modify elements nor invalidate iterators or
5033
- subranges.[^17]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5034
 
5035
  ### Partial sum <a id="partial.sum">[[partial.sum]]</a>
5036
 
5037
  ``` cpp
5038
  template <class InputIterator, class OutputIterator>
5039
  OutputIterator partial_sum(
5040
  InputIterator first, InputIterator last,
5041
  OutputIterator result);
5042
- template
5043
- <class InputIterator, class OutputIterator, class BinaryOperation>
5044
  OutputIterator partial_sum(
5045
  InputIterator first, InputIterator last,
5046
  OutputIterator result, BinaryOperation binary_op);
5047
  ```
5048
 
5049
- *Effects:* For a non-empty range, the function creates an accumulator
5050
- `acc` whose type is `InputIterator`’s value type, initializes it with
5051
- `*first`, and assigns the result to `*result`. For every iterator `i` in
5052
- \[`first + 1`, `last`) in order, `acc` is then modified by
5053
- `acc = acc + *i` or `acc = binary_op(acc, *i)` and the result is
5054
- assigned to `*(result + (i - first))`.
5055
-
5056
- *Returns:* `result + (last - first)`.
5057
-
5058
- *Complexity:* Exactly `(last - first) - 1` applications of the binary
5059
- operation.
5060
-
5061
  *Requires:* `InputIterator`’s value type shall be constructible from the
5062
  type of `*first`. The result of the expression `acc + *i` or
5063
  `binary_op(acc, *i)` shall be implicitly convertible to
5064
- `InputIterator`’s value type. `acc` shall be writable to the `result`
5065
- output iterator. In the ranges \[`first`, `last`\] and
5066
- {\[}\texttt{result}, \texttt{result + (last - first)}{\]} `binary_op`
5067
- shall neither modify elements nor invalidate iterators or
5068
- subranges.[^18]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5069
 
5070
  *Remarks:* `result` may be equal to `first`.
5071
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5072
  ### Adjacent difference <a id="adjacent.difference">[[adjacent.difference]]</a>
5073
 
5074
  ``` cpp
5075
  template <class InputIterator, class OutputIterator>
5076
- OutputIterator adjacent_difference(
5077
- InputIterator first, InputIterator last,
5078
  OutputIterator result);
 
 
 
 
 
 
5079
  template <class InputIterator, class OutputIterator, class BinaryOperation>
5080
- OutputIterator adjacent_difference(
5081
- InputIterator first, InputIterator last,
5082
  OutputIterator result,
5083
  BinaryOperation binary_op);
 
 
 
 
 
 
 
5084
  ```
5085
 
5086
- *Effects:* For a non-empty range, the function creates an accumulator
5087
- `acc` whose type is `InputIterator`’s value type, initializes it with
5088
- `*first`, and assigns the result to `*result`. For every iterator `i` in
5089
- \[`first + 1`, `last`) in order, creates an object `val` whose type is
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5090
  `InputIterator`’s value type, initializes it with `*i`, computes
5091
  `val - acc` or `binary_op(val, acc)`, assigns the result to
5092
  `*(result + (i - first))`, and move assigns from `val` to `acc`.
5093
 
5094
- *Requires:* `InputIterator`’s value type shall be `MoveAssignable`
5095
- (Table  [[moveassignable]]) and shall be constructible from the type of
5096
- `*first`. `acc` shall be writable to the `result` output iterator. The
5097
- result of the expression `val - acc` or `binary_op(val, acc)` shall be
5098
- writable to the `result` output iterator. In the ranges \[`first`,
5099
- `last`\] and \[`result`, `result + (last - first)`\], `binary_op` shall
5100
- neither modify elements nor invalidate iterators or subranges.[^19]
5101
-
5102
- *Remarks:* `result` may be equal to `first`.
5103
 
5104
  *Returns:* `result + (last - first)`.
5105
 
5106
  *Complexity:* Exactly `(last - first) - 1` applications of the binary
5107
  operation.
5108
 
 
 
 
 
 
5109
  ### Iota <a id="numeric.iota">[[numeric.iota]]</a>
5110
 
5111
  ``` cpp
5112
  template <class ForwardIterator, class T>
5113
  void iota(ForwardIterator first, ForwardIterator last, T value);
@@ -5120,252 +5937,1181 @@ The expression `++val`, where `val` has type `T`, shall be well formed.
5120
  \[`first`, `last`), assigns `*i = value` and increments `value` as if by
5121
  `++value`.
5122
 
5123
  *Complexity:* Exactly `last - first` increments and assignments.
5124
 
5125
- ## C library <a id="c.math">[[c.math]]</a>
5126
 
5127
- The header `<ctgmath>` simply includes the headers `<ccomplex>` and
5128
- `<cmath>`.
 
 
5129
 
5130
- The overloads provided in C by type-generic macros are already provided
5131
- in `<ccomplex>` and `<cmath>` by “sufficient” additional overloads.
5132
 
5133
- Tables  [[tab:numerics.hdr.cmath]] and  [[tab:numerics.hdr.cstdlib]]
5134
- describe headers `<cmath>` and `<cstdlib>`, respectively.
 
5135
 
5136
- The contents of these headers are the same as the Standard C library
5137
- headers `<math.h>` and `<stdlib.h>` respectively, with the following
5138
- changes:
5139
 
5140
- The `rand` function has the semantics specified in the C standard,
5141
- except that the implementation may specify that particular library
5142
- functions may call `rand`. It is implementation-defined whether the
5143
- `rand` function may introduce data races ([[res.on.data.races]]). The
5144
- random number generation ([[rand]]) facilities in this standard are
5145
- often preferable to `rand`, because `rand`’s underlying algorithm is
5146
- unspecified. Use of `rand` therefore continues to be nonportable, with
5147
- unpredictable and oft-questionable quality and performance.
5148
 
5149
- In addition to the `int` versions of certain math functions in
5150
- `<cstdlib>`, C++adds `long` and `long long` overloaded versions of these
5151
- functions, with the same semantics.
5152
 
5153
- The added signatures are:
5154
 
5155
  ``` cpp
5156
- long abs(long); // labs()
5157
- long long abs(long long); // llabs()
5158
- ldiv_t div(long, long); // ldiv()
5159
- lldiv_t div(long long, long long); // lldiv()
5160
  ```
5161
 
5162
- In addition to the `double` versions of the math functions in `<cmath>`,
5163
- C++adds `float` and `long double` overloaded versions of these
5164
- functions, with the same semantics.
5165
 
5166
- The added signatures are:
 
5167
 
5168
- ``` cpp
5169
- float abs(float);
5170
- float acos(float);
5171
- float acosh(float);
5172
- float asin(float);
5173
- float asinh(float);
5174
- float atan(float);
5175
- float atan2(float, float);
5176
- float atanh(float);
5177
- float cbrt(float);
5178
- float ceil(float);
5179
- float copysign(float, float);
5180
- float cos(float);
5181
- float cosh(float);
5182
- float erf(float);
5183
- float erfc(float);
5184
- float exp(float);
5185
- float exp2(float);
5186
- float expm1(float);
5187
- float fabs(float);
5188
- float fdim(float, float);
5189
- float floor(float);
5190
- float fma(float, float, float);
5191
- float fmax(float, float);
5192
- float fmin(float, float);
5193
- float fmod(float, float);
5194
- float frexp(float, int*);
5195
- float hypot(float, float);
5196
- int ilogb(float);
5197
- float ldexp(float, int);
5198
- float lgamma(float);
5199
- long long llrint(float);
5200
- long long llround(float);
5201
- float log(float);
5202
- float log10(float);
5203
- float log1p(float);
5204
- float log2(float);
5205
- float logb(float);
5206
- long lrint(float);
5207
- long lround(float);
5208
- float modf(float, float*);
5209
- float nearbyint(float);
5210
- float nextafter(float, float);
5211
- float nexttoward(float, long double);
5212
- float pow(float, float);
5213
- float remainder(float, float);
5214
- float remquo(float, float, int *);
5215
- float rint(float);
5216
- float round(float);
5217
- float scalbln(float, long);
5218
- float scalbn(float, int);
5219
- float sin(float);
5220
- float sinh(float);
5221
- float sqrt(float);
5222
- float tan(float);
5223
- float tanh(float);
5224
- float tgamma(float);
5225
- float trunc(float);
5226
-
5227
- double abs(double); // fabs()
5228
-
5229
- long double abs(long double);
5230
- long double acos(long double);
5231
- long double acosh(long double);
5232
- long double asin(long double);
5233
- long double asinh(long double);
5234
- long double atan(long double);
5235
- long double atan2(long double, long double);
5236
- long double atanh(long double);
5237
- long double cbrt(long double);
5238
- long double ceil(long double);
5239
- long double copysign(long double, long double);
5240
- long double cos(long double);
5241
- long double cosh(long double);
5242
- long double erf(long double);
5243
- long double erfc(long double);
5244
- long double exp(long double);
5245
- long double exp2(long double);
5246
- long double expm1(long double);
5247
- long double fabs(long double);
5248
- long double fdim(long double, long double);
5249
- long double floor(long double);
5250
- long double fma(long double, long double, long double);
5251
- long double fmax(long double, long double);
5252
- long double fmin(long double, long double);
5253
- long double fmod(long double, long double);
5254
- long double frexp(long double, int*);
5255
- long double hypot(long double, long double);
5256
- int ilogb(long double);
5257
- long double ldexp(long double, int);
5258
- long double lgamma(long double);
5259
- long long llrint(long double);
5260
- long long llround(long double);
5261
- long double log(long double);
5262
- long double log10(long double);
5263
- long double log1p(long double);
5264
- long double log2(long double);
5265
- long double logb(long double);
5266
- long lrint(long double);
5267
- long lround(long double);
5268
- long double modf(long double, long double*);
5269
- long double nearbyint(long double);
5270
- long double nextafter(long double, long double);
5271
- long double nexttoward(long double, long double);
5272
- long double pow(long double, long double);
5273
- long double remainder(long double, long double);
5274
- long double remquo(long double, long double, int *);
5275
- long double rint(long double);
5276
- long double round(long double);
5277
- long double scalbln(long double, long);
5278
- long double scalbn(long double, int);
5279
- long double sin(long double);
5280
- long double sinh(long double);
5281
- long double sqrt(long double);
5282
- long double tan(long double);
5283
- long double tanh(long double);
5284
- long double tgamma(long double);
5285
- long double trunc(long double);
5286
- ```
5287
 
5288
- The classification/comparison functions behave the same as the C macros
5289
- with the corresponding names defined in 7.12.3, Classification macros,
5290
- and 7.12.14, Comparison macros in the C Standard. Each function is
5291
- overloaded for the three floating-point types, as follows:
5292
 
5293
  ``` cpp
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5294
  int fpclassify(float x);
5295
- bool isfinite(float x);
5296
- bool isinf(float x);
5297
- bool isnan(float x);
5298
- bool isnormal(float x);
5299
- bool signbit(float x);
5300
-
5301
- bool isgreater(float x, float y);
5302
- bool isgreaterequal(float x, float y);
5303
- bool isless(float x, float y);
5304
- bool islessequal(float x, float y);
5305
- bool islessgreater(float x, float y);
5306
- bool isunordered(float x, float y);
5307
-
5308
  int fpclassify(double x);
5309
- bool isfinite(double x);
5310
- bool isinf(double x);
5311
- bool isnan(double x);
5312
- bool isnormal(double x);
5313
- bool signbit(double x);
5314
-
5315
- bool isgreater(double x, double y);
5316
- bool isgreaterequal(double x, double y);
5317
- bool isless(double x, double y);
5318
- bool islessequal(double x, double y);
5319
- bool islessgreater(double x, double y);
5320
- bool isunordered(double x, double y);
5321
-
5322
  int fpclassify(long double x);
5323
- bool isfinite(long double x);
5324
- bool isinf(long double x);
5325
- bool isnan(long double x);
5326
- bool isnormal(long double x);
5327
- bool signbit(long double x);
5328
-
5329
- bool isgreater(long double x, long double y);
5330
- bool isgreaterequal(long double x, long double y);
5331
- bool isless(long double x, long double y);
5332
- bool islessequal(long double x, long double y);
5333
- bool islessgreater(long double x, long double y);
5334
- bool isunordered(long double x, long double y);
5335
- ```
5336
-
5337
- Moreover, there shall be additional overloads sufficient to ensure:
5338
-
5339
- 1. If any arithmetic argument corresponding to a `double` parameter has
5340
- type `long double`, then all arithmetic arguments corresponding to
5341
- `double` parameters are effectively cast to `long double`.
5342
- 2. Otherwise, if any arithmetic argument corresponding to a `double`
5343
- parameter has type `double` or an integer type, then all arithmetic
5344
- arguments corresponding to `double` parameters are effectively cast
5345
- to `double`.
5346
- 3. Otherwise, all arithmetic arguments corresponding to `double`
5347
- parameters have type `float`.
5348
-
5349
- ISO C 7.5, 7.10.2, 7.10.6.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5350
 
5351
  <!-- Link reference definitions -->
5352
  [accumulate]: #accumulate
5353
  [adjacent.difference]: #adjacent.difference
5354
  [algorithms]: algorithms.md#algorithms
5355
  [bad.alloc]: language.md#bad.alloc
5356
  [basic.fundamental]: basic.md#basic.fundamental
5357
  [basic.stc.thread]: basic.md#basic.stc.thread
5358
  [basic.types]: basic.md#basic.types
5359
  [c.math]: #c.math
5360
- [ccmplx]: #ccmplx
 
 
 
5361
  [cfenv]: #cfenv
5362
  [cfenv.syn]: #cfenv.syn
5363
  [class.gslice]: #class.gslice
5364
  [class.gslice.overview]: #class.gslice.overview
5365
  [class.slice]: #class.slice
5366
  [class.slice.overview]: #class.slice.overview
 
5367
  [cmplx.over]: #cmplx.over
5368
  [complex]: #complex
5369
  [complex.literals]: #complex.literals
5370
  [complex.member.ops]: #complex.member.ops
5371
  [complex.members]: #complex.members
@@ -5374,39 +7120,48 @@ ISO C 7.5, 7.10.2, 7.10.6.
5374
  [complex.special]: #complex.special
5375
  [complex.syn]: #complex.syn
5376
  [complex.transcendentals]: #complex.transcendentals
5377
  [complex.value.ops]: #complex.value.ops
5378
  [cons.slice]: #cons.slice
5379
- [copyassignable]: #copyassignable
5380
- [copyconstructible]: #copyconstructible
 
 
5381
  [dcl.init]: dcl.md#dcl.init
5382
- [equalitycomparable]: #equalitycomparable
5383
  [function.objects]: utilities.md#function.objects
5384
  [gslice.access]: #gslice.access
5385
  [gslice.array.assign]: #gslice.array.assign
5386
  [gslice.array.comp.assign]: #gslice.array.comp.assign
5387
  [gslice.array.fill]: #gslice.array.fill
5388
  [gslice.cons]: #gslice.cons
 
 
5389
  [indirect.array.assign]: #indirect.array.assign
5390
  [indirect.array.comp.assign]: #indirect.array.comp.assign
5391
  [indirect.array.fill]: #indirect.array.fill
5392
  [inner.product]: #inner.product
 
5393
  [input.output]: input.md#input.output
5394
  [iostate.flags]: input.md#iostate.flags
5395
  [istream.formatted]: input.md#istream.formatted
5396
- [limits]: language.md#limits
 
5397
  [mask.array.assign]: #mask.array.assign
5398
  [mask.array.comp.assign]: #mask.array.comp.assign
5399
  [mask.array.fill]: #mask.array.fill
5400
- [moveassignable]: #moveassignable
5401
  [numarray]: #numarray
5402
  [numeric.iota]: #numeric.iota
5403
  [numeric.ops]: #numeric.ops
 
 
5404
  [numeric.ops.overview]: #numeric.ops.overview
5405
  [numeric.requirements]: #numeric.requirements
5406
  [numerics]: #numerics
 
5407
  [numerics.general]: #numerics.general
 
5408
  [partial.sum]: #partial.sum
5409
  [rand]: #rand
5410
  [rand.adapt]: #rand.adapt
5411
  [rand.adapt.disc]: #rand.adapt.disc
5412
  [rand.adapt.general]: #rand.adapt.general
@@ -5455,25 +7210,49 @@ ISO C 7.5, 7.10.2, 7.10.6.
5455
  [rand.synopsis]: #rand.synopsis
5456
  [rand.util]: #rand.util
5457
  [rand.util.canonical]: #rand.util.canonical
5458
  [rand.util.seedseq]: #rand.util.seedseq
5459
  [random.access.iterators]: iterators.md#random.access.iterators
 
5460
  [res.on.data.races]: library.md#res.on.data.races
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5461
  [slice.access]: #slice.access
5462
  [slice.arr.assign]: #slice.arr.assign
5463
  [slice.arr.comp.assign]: #slice.arr.comp.assign
5464
  [slice.arr.fill]: #slice.arr.fill
5465
  [strings]: strings.md#strings
5466
  [tab:RandomDistribution]: #tab:RandomDistribution
5467
  [tab:RandomEngine]: #tab:RandomEngine
5468
  [tab:SeedSequence]: #tab:SeedSequence
5469
- [tab:UniformRandomNumberGenerator]: #tab:UniformRandomNumberGenerator
 
 
 
5470
  [tab:iterator.input.requirements]: iterators.md#tab:iterator.input.requirements
5471
- [tab:iterator.output.requirements]: iterators.md#tab:iterator.output.requirements
5472
- [tab:iterator.random.access.requirements]: iterators.md#tab:iterator.random.access.requirements
5473
- [tab:numerics.hdr.cmath]: #tab:numerics.hdr.cmath
5474
- [tab:numerics.hdr.cstdlib]: #tab:numerics.hdr.cstdlib
5475
  [tab:numerics.lib.summary]: #tab:numerics.lib.summary
5476
  [template.gslice.array]: #template.gslice.array
5477
  [template.gslice.array.overview]: #template.gslice.array.overview
5478
  [template.indirect.array]: #template.indirect.array
5479
  [template.indirect.array.overview]: #template.indirect.array.overview
@@ -5482,10 +7261,13 @@ ISO C 7.5, 7.10.2, 7.10.6.
5482
  [template.slice.array]: #template.slice.array
5483
  [template.slice.array.overview]: #template.slice.array.overview
5484
  [template.valarray]: #template.valarray
5485
  [template.valarray.overview]: #template.valarray.overview
5486
  [thread.thread.class]: thread.md#thread.thread.class
 
 
 
5487
  [valarray.access]: #valarray.access
5488
  [valarray.assign]: #valarray.assign
5489
  [valarray.binary]: #valarray.binary
5490
  [valarray.cassign]: #valarray.cassign
5491
  [valarray.comparison]: #valarray.comparison
@@ -5521,53 +7303,51 @@ ISO C 7.5, 7.10.2, 7.10.6.
5521
  [^6]: The distribution corresponding to this probability density
5522
  function is also known (with a possible change of variable) as the
5523
  Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I
5524
  distribution.
5525
 
5526
- [^7]: Clause  [[limits]] recommends a minimum number of recursively
5527
  nested template instantiations. This requirement thus indirectly
5528
  suggests a minimum allowable complexity for valarray expressions.
5529
 
5530
  [^8]: The intent is to specify an array template that has the minimum
5531
  functionality necessary to address aliasing ambiguities and the
5532
  proliferation of temporaries. Thus, the `valarray` template is
5533
  neither a matrix class nor a field class. However, it is a very
5534
  useful building block for designing such classes.
5535
 
5536
- [^9]: For convenience, such objects are referred to as “arrays”
5537
- throughout the remainder of [[numarray]].
5538
-
5539
- [^10]: This default constructor is essential, since arrays of `valarray`
5540
  may be useful. After initialization, the length of an empty array
5541
  can be increased with the `resize` member function.
5542
 
5543
- [^11]: This constructor is the preferred method for converting a C array
5544
  to a `valarray` object.
5545
 
5546
- [^12]: This copy constructor creates a distinct array rather than an
5547
  alias. Implementations in which arrays share storage are permitted,
5548
  but they shall implement a copy-on-reference mechanism to ensure
5549
  that arrays are conceptually distinct.
5550
 
5551
- [^13]: Compilers may take advantage of inlining, constant propagation,
5552
- loop fusion, tracking of pointers obtained from `operator new`, and
5553
- other techniques to generate efficient `valarray`s.
5554
-
5555
- [^14]: BLAS stands for *Basic Linear Algebra Subprograms.* C++programs
5556
  may instantiate this class. See, for example, Dongarra, Du Croz,
5557
  Duff, and Hammerling: *A set of Level 3 Basic Linear Algebra
5558
  Subprograms*; Technical Report MCS-P1-0888, Argonne National
5559
  Laboratory (USA), Mathematics and Computer Science Division, August,
5560
  1988.
5561
 
5562
- [^15]: `accumulate` is similar to the APL reduction operator and Common
 
 
5563
  Lisp reduce function, but it avoids the difficulty of defining the
5564
  result of reduction on an empty sequence by always requiring an
5565
  initial value.
5566
 
5567
- [^16]: The use of fully closed ranges is intentional
5568
 
5569
- [^17]: The use of fully closed ranges is intentional
5570
 
5571
- [^18]: The use of fully closed ranges is intentional.
5572
 
5573
- [^19]: The use of fully closed ranges is intentional.
 
 
 
 
5
  This Clause describes components that C++programs may use to perform
6
  seminumerical operations.
7
 
8
  The following subclauses describe components for complex number types,
9
  random number generation, numeric ( *n*-at-a-time) arrays, generalized
10
+ numeric algorithms, and mathematical functions for floating-point types,
11
+ as summarized in Table  [[tab:numerics.lib.summary]].
12
 
13
  **Table: Numerics library summary** <a id="tab:numerics.lib.summary">[tab:numerics.lib.summary]</a>
14
 
15
  | Subclause | | Header |
16
  | ------------------------ | ------------------------------ | ------------ |
17
+ | [[numerics.defns]] | Definitions | |
18
  | [[numeric.requirements]] | Requirements | |
19
+ | [[cfenv]] | Floating-point environment | `<cfenv>` |
20
+ | [[complex.numbers]] | Complex numbers | `<complex>` |
21
  | [[rand]] | Random number generation | `<random>` |
22
  | [[numarray]] | Numeric arrays | `<valarray>` |
23
  | [[numeric.ops]] | Generalized numeric operations | `<numeric>` |
24
+ | [[c.math]] | Mathematical functions for | `<cmath>` |
25
+ | | floating-point types | `<cstdlib>` |
 
 
26
 
27
 
28
+ ## Definitions <a id="numerics.defns">[[numerics.defns]]</a>
29
+
30
+ Define `GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aN)` as follows:
31
+
32
+ - `a1` when `N` is `1`, otherwise
33
+ - `op(GENERALIZED_NONCOMMUTATIVE_SUM(op, a1, ..., aK),`
34
+ `\phantom{op(}GENERALIZED_NONCOMMUTATIVE_SUM(op, aM, ..., aN))` for
35
+ any `K` where 1 < K+1 = M ≤ N.
36
+
37
+ Define `GENERALIZED_SUM(op, a1, ..., aN)` as
38
+ `GENERALIZED_NONCOMMUTATIVE_SUM(op, b1, ..., bN)`, where `b1, ..., bN`
39
+ may be any permutation of `a1, ..., aN`.
40
+
41
  ## Numeric type requirements <a id="numeric.requirements">[[numeric.requirements]]</a>
42
 
43
  The `complex` and `valarray` components are parameterized by the type of
44
  information they contain and manipulate. A C++program shall instantiate
45
  these components only with a type `T` that satisfies the following
 
55
  - If `T` is a class, it has a public destructor;
56
  - If `T` is a class, it has a public assignment operator whose signature
57
  is either `T& T::operator=(const T&)` or `T& T::operator=(T)`
58
  - If `T` is a class, its assignment operator, copy and default
59
  constructors, and destructor shall correspond to each other in the
60
+ following sense:
61
+ - Initialization of raw storage using the copy constructor on the
62
+ value of `T()`, however obtained, is semantically equivalent to
63
+ value-initialization of the same raw storage.
64
+ - Initialization of raw storage using the default constructor,
65
+ followed by assignment, is semantically equivalent to initialization
66
+ of raw storage using the copy constructor.
67
+ - Destruction of an object, followed by initialization of its raw
68
+ storage using the copy constructor, is semantically equivalent to
69
+ assignment to the original object.
70
+
71
+ \[*Note 1*:
72
+ This rule states, in part, that there shall not be any subtle
73
  differences in the semantics of initialization versus assignment. This
74
  gives an implementation considerable flexibility in how arrays are
75
+ initialized.
76
+ \[*Example 1*:
77
+ An implementation is allowed to initialize a `valarray` by allocating
78
+ storage using the `new` operator (which implies a call to the default
79
+ constructor for each element) and then assigning each element its
80
+ value. Or the implementation can allocate raw storage and use the copy
81
+ constructor to initialize each element.
82
+ *end example*]
83
+ If the distinction between initialization and assignment is important
84
+ for a class, or if it fails to satisfy any of the other conditions
85
+ listed above, the programmer should use `vector` ([[vector]]) instead
86
+ of `valarray` for that class.
87
+ — *end note*]
88
  - If `T` is a class, it does not overload unary `operator&`.
89
 
90
  If any operation on `T` throws an exception the effects are undefined.
91
 
92
  In addition, many member and related functions of `valarray<T>` can be
93
  successfully instantiated and will exhibit well-defined behavior if and
94
  only if `T` satisfies additional requirements specified for each such
95
  member or related function.
96
 
97
+ [*Example 2*: It is valid to instantiate `valarray<complex>`, but
98
+ `operator>()` will not be successfully instantiated for
99
+ `valarray<complex>` operands, since `complex` does not have any ordering
100
+ operators. — *end example*]
101
 
102
  ## The floating-point environment <a id="cfenv">[[cfenv]]</a>
103
 
104
  ### Header `<cfenv>` synopsis <a id="cfenv.syn">[[cfenv.syn]]</a>
105
 
106
  ``` cpp
107
+ #define FE_ALL_EXCEPT see below
108
+ #define FE_DIVBYZERO see below
109
+ #define FE_INEXACT see below
110
+ #define FE_INVALID see below
111
+ #define FE_OVERFLOW see below
112
+ #define FE_UNDERFLOW see below
113
+
114
+ #define FE_DOWNWARD see below
115
+ #define FE_TONEAREST see below
116
+ #define FE_TOWARDZERO see below
117
+ #define FE_UPWARD see below
118
+
119
+ #define FE_DFL_ENV see below
120
+
121
  namespace std {
122
  // types
123
+ using fenv_t = object type;
124
+ using fexcept_t = integer type;
125
 
126
  // functions
127
  int feclearexcept(int except);
128
  int fegetexceptflag(fexcept_t* pflag, int except);
129
  int feraiseexcept(int except);
130
  int fesetexceptflag(const fexcept_t* pflag, int except);
131
  int fetestexcept(int except);
132
 
133
+ int fegetround();
134
  int fesetround(int mode);
135
 
136
  int fegetenv(fenv_t* penv);
137
  int feholdexcept(fenv_t* penv);
138
  int fesetenv(const fenv_t* penv);
139
  int feupdateenv(const fenv_t* penv);
140
  }
141
  ```
142
 
143
+ The contents and meaning of the header `<cfenv>` are the same as the C
144
+ standard library header `<fenv.h>`.
145
+
146
+ [*Note 1*: This International Standard does not require an
147
+ implementation to support the `FENV_ACCESS` pragma; it is
148
+ *implementation-defined* ([[cpp.pragma]]) whether the pragma is
149
+ supported. As a consequence, it is *implementation-defined* whether
150
+ these functions can be used to test floating-point status flags, set
151
+ floating-point control modes, or run under non-default mode settings. If
152
+ the pragma is used to enable control over the floating-point
153
+ environment, this International Standard does not specify the effect on
154
+ floating-point evaluation in constant expressions. — *end note*]
 
 
 
 
 
 
 
 
155
 
156
  The floating-point environment has thread storage duration (
157
  [[basic.stc.thread]]). The initial state for a thread’s floating-point
158
  environment is the state of the floating-point environment of the thread
159
+ that constructs the corresponding `thread` object (
160
+ [[thread.thread.class]]) at the time it constructed the object.
161
+
162
+ [*Note 2*: That is, the child thread gets the floating-point state of
163
+ the parent thread at the time of the child’s creation. — *end note*]
164
 
165
  A separate floating-point environment shall be maintained for each
166
  thread. Each function accesses the environment corresponding to its
167
  calling thread.
168
 
169
+ ISO C 7.6
170
+
171
  ## Complex numbers <a id="complex.numbers">[[complex.numbers]]</a>
172
 
173
  The header `<complex>` defines a class template, and numerous functions
174
  for representing and manipulating complex numbers.
175
 
 
179
  `complex<long double>` are literal types ([[basic.types]]).
180
 
181
  If the result of a function is not mathematically defined or not in the
182
  range of representable values for its type, the behavior is undefined.
183
 
184
+ If `z` is an lvalue expression of type cv `complex<T>` then:
185
 
186
  - the expression `reinterpret_cast<cv T(&)[2]>(z)` shall be well-formed,
187
  - `reinterpret_cast<cv T(&)[2]>(z)[0]` shall designate the real part of
188
  `z`, and
189
  - `reinterpret_cast<cv T(&)[2]>(z)[1]` shall designate the imaginary
190
  part of `z`.
191
 
192
+ Moreover, if `a` is an expression of type cv `complex<T>*` and the
193
  expression `a[i]` is well-defined for an integer expression `i`, then:
194
 
195
  - `reinterpret_cast<cv T*>(a)[2*i]` shall designate the real part of
196
  `a[i]`, and
197
  - `reinterpret_cast<cv T*>(a)[2*i + 1]` shall designate the imaginary
 
204
  template<class T> class complex;
205
  template<> class complex<float>;
206
  template<> class complex<double>;
207
  template<> class complex<long double>;
208
 
209
+ // [complex.ops], operators
210
  template<class T>
211
  complex<T> operator+(const complex<T>&, const complex<T>&);
212
  template<class T> complex<T> operator+(const complex<T>&, const T&);
213
  template<class T> complex<T> operator+(const T&, const complex<T>&);
214
 
 
245
 
246
  template<class T, class charT, class traits>
247
  basic_ostream<charT, traits>&
248
  operator<<(basic_ostream<charT, traits>&, const complex<T>&);
249
 
250
+ // [complex.value.ops], values
251
  template<class T> constexpr T real(const complex<T>&);
252
  template<class T> constexpr T imag(const complex<T>&);
253
 
254
  template<class T> T abs(const complex<T>&);
255
  template<class T> T arg(const complex<T>&);
 
257
 
258
  template<class T> complex<T> conj(const complex<T>&);
259
  template<class T> complex<T> proj(const complex<T>&);
260
  template<class T> complex<T> polar(const T&, const T& = 0);
261
 
262
+ // [complex.transcendentals], transcendentals
263
  template<class T> complex<T> acos(const complex<T>&);
264
  template<class T> complex<T> asin(const complex<T>&);
265
  template<class T> complex<T> atan(const complex<T>&);
266
 
267
  template<class T> complex<T> acosh(const complex<T>&);
 
282
  template<class T> complex<T> sinh (const complex<T>&);
283
  template<class T> complex<T> sqrt (const complex<T>&);
284
  template<class T> complex<T> tan (const complex<T>&);
285
  template<class T> complex<T> tanh (const complex<T>&);
286
 
287
+ // [complex.literals], complex literals
288
  inline namespace literals {
289
  inline namespace complex_literals {
290
  constexpr complex<long double> operator""il(long double);
291
  constexpr complex<long double> operator""il(unsigned long long);
292
  constexpr complex<double> operator""i(long double);
 
303
  ``` cpp
304
  namespace std {
305
  template<class T>
306
  class complex {
307
  public:
308
+ using value_type = T;
309
 
310
  constexpr complex(const T& re = T(), const T& im = T());
311
  constexpr complex(const complex&);
312
  template<class X> constexpr complex(const complex<X>&);
313
 
 
339
 
340
  ``` cpp
341
  namespace std {
342
  template<> class complex<float> {
343
  public:
344
+ using value_type = float;
345
 
346
  constexpr complex(float re = 0.0f, float im = 0.0f);
347
  constexpr explicit complex(const complex<double>&);
348
  constexpr explicit complex(const complex<long double>&);
349
 
 
366
  template<class X> complex<float>& operator/=(const complex<X>&);
367
  };
368
 
369
  template<> class complex<double> {
370
  public:
371
+ using value_type = double;
372
 
373
  constexpr complex(double re = 0.0, double im = 0.0);
374
  constexpr complex(const complex<float>&);
375
  constexpr explicit complex(const complex<long double>&);
376
 
 
393
  template<class X> complex<double>& operator/=(const complex<X>&);
394
  };
395
 
396
  template<> class complex<long double> {
397
  public:
398
+ using value_type = long double;
399
 
400
  constexpr complex(long double re = 0.0L, long double im = 0.0L);
401
  constexpr complex(const complex<float>&);
402
  constexpr complex(const complex<double>&);
403
 
 
428
  template<class T> constexpr complex(const T& re = T(), const T& im = T());
429
  ```
430
 
431
  *Effects:* Constructs an object of class `complex`.
432
 
433
+ *Postconditions:* `real() == re && imag() == im`.
434
 
435
  ``` cpp
436
  constexpr T real() const;
437
  ```
438
 
 
536
 
537
  ``` cpp
538
  template<class T> complex<T> operator+(const complex<T>& lhs);
539
  ```
540
 
 
 
541
  *Returns:* `complex<T>(lhs)`.
542
 
543
+ *Remarks:* unary operator.
544
+
545
  ``` cpp
546
+ template<class T> complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
 
547
  template<class T> complex<T> operator+(const complex<T>& lhs, const T& rhs);
548
  template<class T> complex<T> operator+(const T& lhs, const complex<T>& rhs);
549
  ```
550
 
551
  *Returns:* `complex<T>(lhs) += rhs`.
552
 
553
  ``` cpp
554
  template<class T> complex<T> operator-(const complex<T>& lhs);
555
  ```
556
 
 
 
557
  *Returns:* `complex<T>(-lhs.real(),-lhs.imag())`.
558
 
559
+ *Remarks:* unary operator.
560
+
561
  ``` cpp
562
+ template<class T> complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
 
563
  template<class T> complex<T> operator-(const complex<T>& lhs, const T& rhs);
564
  template<class T> complex<T> operator-(const T& lhs, const complex<T>& rhs);
565
  ```
566
 
567
  *Returns:* `complex<T>(lhs) -= rhs`.
568
 
569
  ``` cpp
570
+ template<class T> complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
 
571
  template<class T> complex<T> operator*(const complex<T>& lhs, const T& rhs);
572
  template<class T> complex<T> operator*(const T& lhs, const complex<T>& rhs);
573
  ```
574
 
575
  *Returns:* `complex<T>(lhs) *= rhs`.
576
 
577
  ``` cpp
578
+ template<class T> complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
 
579
  template<class T> complex<T> operator/(const complex<T>& lhs, const T& rhs);
580
  template<class T> complex<T> operator/(const T& lhs, const complex<T>& rhs);
581
  ```
582
 
583
  *Returns:* `complex<T>(lhs) /= rhs`.
584
 
585
  ``` cpp
586
+ template<class T> constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
 
587
  template<class T> constexpr bool operator==(const complex<T>& lhs, const T& rhs);
588
  template<class T> constexpr bool operator==(const T& lhs, const complex<T>& rhs);
589
  ```
590
 
591
  *Returns:* `lhs.real() == rhs.real() && lhs.imag() == rhs.imag()`.
592
 
593
  *Remarks:* The imaginary part is assumed to be `T()`, or 0.0, for the
594
  `T` arguments.
595
 
596
  ``` cpp
597
+ template<class T> constexpr bool operator!=(const complex<T>& lhs, const complex<T>& rhs);
 
598
  template<class T> constexpr bool operator!=(const complex<T>& lhs, const T& rhs);
599
  template<class T> constexpr bool operator!=(const T& lhs, const complex<T>& rhs);
600
  ```
601
 
602
  *Returns:* `rhs.real() != lhs.real() || rhs.imag() != lhs.imag()`.
 
605
  template<class T, class charT, class traits>
606
  basic_istream<charT, traits>&
607
  operator>>(basic_istream<charT, traits>& is, complex<T>& x);
608
  ```
609
 
610
+ *Requires:* The input values shall be convertible to `T`.
611
+
612
  *Effects:* Extracts a complex number `x` of the form: `u`, `(u)`, or
613
  `(u,v)`, where `u` is the real part and `v` is the imaginary
614
  part ([[istream.formatted]]).
615
 
 
 
616
  If bad input is encountered, calls `is.setstate(ios_base::failbit)`
617
  (which may throw `ios::failure` ([[iostate.flags]])).
618
 
619
  *Returns:* `is`.
620
 
 
626
  template<class T, class charT, class traits>
627
  basic_ostream<charT, traits>&
628
  operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
629
  ```
630
 
631
+ *Effects:* Inserts the complex number `x` onto the stream `o` as if it
632
  were implemented as follows:
633
 
634
  ``` cpp
 
 
 
635
  basic_ostringstream<charT, traits> s;
636
  s.flags(o.flags());
637
  s.imbue(o.getloc());
638
  s.precision(o.precision());
639
  s << '(' << x.real() << "," << x.imag() << ')';
640
  return o << s.str();
 
641
  ```
642
 
643
+ [*Note 1*: In a locale in which comma is used as a decimal point
644
+ character, the use of comma as a field separator can be ambiguous.
645
+ Inserting `showpoint` into the output stream forces all outputs to show
646
+ an explicit decimal point character; as a result, all inserted sequences
647
+ of complex numbers can be extracted unambiguously. — *end note*]
648
 
649
  ### `complex` value operations <a id="complex.value.ops">[[complex.value.ops]]</a>
650
 
651
  ``` cpp
652
  template<class T> constexpr T real(const complex<T>& x);
 
695
 
696
  ``` cpp
697
  template<class T> complex<T> polar(const T& rho, const T& theta = 0);
698
  ```
699
 
700
+ *Requires:* `rho` shall be non-negative and non-NaN. `theta` shall be
701
+ finite.
702
+
703
  *Returns:* The `complex` value corresponding to a complex number whose
704
  magnitude is `rho` and whose phase angle is `theta`.
705
 
706
  ### `complex` transcendentals <a id="complex.transcendentals">[[complex.transcendentals]]</a>
707
 
 
767
 
768
  ``` cpp
769
  template<class T> complex<T> exp(const complex<T>& x);
770
  ```
771
 
772
+ *Returns:* The complex base-e exponential of `x`.
773
 
774
  ``` cpp
775
  template<class T> complex<T> log(const complex<T>& x);
776
  ```
777
 
778
+ *Returns:* The complex natural (base-e) logarithm of `x`. For all `x`,
779
+ `imag(log(x))` lies in the interval \[-π, π\], and when `x` is a
780
+ negative real number, `imag(log(x))` is π.
781
 
782
+ *Remarks:* The branch cuts are along the negative real axis.
 
 
 
783
 
784
  ``` cpp
785
  template<class T> complex<T> log10(const complex<T>& x);
786
  ```
787
 
788
+ *Returns:* The complex common (base-10) logarithm of `x`, defined as
 
 
789
  `log(x) / log(10)`.
790
 
791
+ *Remarks:* The branch cuts are along the negative real axis.
792
+
793
  ``` cpp
794
+ template<class T> complex<T> pow(const complex<T>& x, const complex<T>& y);
 
795
  template<class T> complex<T> pow(const complex<T>& x, const T& y);
796
  template<class T> complex<T> pow(const T& x, const complex<T>& y);
797
  ```
798
 
799
+ *Returns:* The complex power of base `x` raised to the `y`ᵗʰ power,
 
 
800
  defined as `exp(y * log(x))`. The value returned for `pow(0, 0)` is
801
+ *implementation-defined*.
802
+
803
+ *Remarks:* The branch cuts are along the negative real axis.
804
 
805
  ``` cpp
806
  template<class T> complex<T> sin(const complex<T>& x);
807
  ```
808
 
 
816
 
817
  ``` cpp
818
  template<class T> complex<T> sqrt(const complex<T>& x);
819
  ```
820
 
 
 
821
  *Returns:* The complex square root of `x`, in the range of the right
822
  half-plane. If the argument is a negative real number, the value
823
  returned lies on the positive imaginary axis.
824
 
825
+ *Remarks:* The branch cuts are along the negative real axis.
826
+
827
  ``` cpp
828
  template<class T> complex<T> tan(const complex<T>& x);
829
  ```
830
 
831
  *Returns:* The complex tangent of `x`.
 
894
  constexpr complex<float> operator""if(unsigned long long d);
895
  ```
896
 
897
  *Returns:* `complex<float>{0.0f, static_cast<float>(d)}`.
898
 
 
 
 
 
899
  ## Random number generation <a id="rand">[[rand]]</a>
900
 
901
  This subclause defines a facility for generating (pseudo-)random
902
  numbers.
903
 
904
  In addition to a few utilities, four categories of entities are
905
+ described: *uniform random bit generators*, *random number engines*,
906
  *random number engine adaptors*, and *random number distributions*.
907
  These categorizations are applicable to types that satisfy the
908
  corresponding requirements, to objects instantiated from such types, and
909
+ to templates producing such types when instantiated.
910
+
911
+ [*Note 1*: These entities are specified in such a way as to permit the
912
+ binding of any uniform random bit generator object `e` as the argument
913
+ to any random number distribution object `d`, thus producing a
914
+ zero-argument function object such as given by
915
+ `bind(d,e)`. — *end note*]
916
 
917
  Each of the entities specified via this subclause has an associated
918
  arithmetic type ([[basic.fundamental]]) identified as `result_type`.
919
  With `T` as the `result_type` thus associated with such an entity, that
920
  entity is characterized:
 
936
  template:
937
 
938
  Throughout this subclause [[rand]], phrases of the form “`x` is an
939
  iterator of a specific kind” shall be interpreted as equivalent to the
940
  more formal requirement that “`x` is a value of a type satisfying the
941
+ requirements of the specified iterator type”.
942
 
943
  Throughout this subclause [[rand]], any constructor that can be called
944
  with a single argument and that satisfies a requirement specified in
945
  this subclause shall be declared `explicit`.
946
 
947
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
948
 
949
  A *seed sequence* is an object that consumes a sequence of
950
  integer-valued data and produces a requested number of unsigned integer
951
+ values i, 0 ≤ i < 2³², based on the consumed data.
952
+
953
+ [*Note 1*: Such an object provides a mechanism to avoid replication of
954
+ streams of random variates. This can be useful, for example, in
955
+ applications requiring large numbers of random number
956
+ engines. — *end note*]
957
 
958
  A class `S` satisfies the requirements of a seed sequence if the
959
  expressions shown in Table  [[tab:SeedSequence]] are valid and have the
960
  indicated semantics, and if `S` also satisfies all other requirements of
961
  this section [[rand.req.seedseq]]. In that Table and throughout this
962
  section:
963
 
964
+ #### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
965
 
966
+ A *uniform random bit generator* `g` of type `G` is a function object
967
  returning unsigned integer values such that each value in the range of
968
+ possible results has (ideally) equal probability of being returned.
 
 
969
 
970
+ [*Note 1*: The degree to which `g`’s results approximate the ideal is
971
+ often determined statistically. — *end note*]
972
+
973
+ A class `G` satisfies the requirements of a *uniform random bit
974
  generator* if the expressions shown in Table 
975
+ [[tab:UniformRandomBitGenerator]] are valid and have the indicated
976
  semantics, and if `G` also satisfies all other requirements of this
977
  section [[rand.req.urng]]. In that Table and throughout this section:
978
 
979
  The following relation shall hold: `G::min() < G::max()`.
980
 
981
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
982
 
983
  A *random number engine* (commonly shortened to *engine*) `e` of type
984
+ `E` is a uniform random bit generator that additionally meets the
985
+ requirements (e.g., for seeding and for input/output) specified in this
986
+ section.
987
 
988
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
989
  construction, `e` has an initial state e₀. An engine’s state may be
990
  established via a constructor, a `seed` function, assignment, or a
991
  suitable `operator>>`.
992
 
993
  `E`’s specification shall define:
994
 
995
+ A class `E` that satisfies the requirements of a uniform random bit
996
  generator ([[rand.req.urng]]) also satisfies the requirements of a
997
  *random number engine* if the expressions shown in Table 
998
  [[tab:RandomEngine]] are valid and have the indicated semantics, and if
999
  `E` also satisfies all other requirements of this section
1000
  [[rand.req.eng]]. In that Table and throughout this section:
1001
 
1002
  where `charT` and `traits` are constrained according to Clause 
1003
  [[strings]] and Clause  [[input.output]].
1004
 
1005
  `E` shall meet the requirements of `CopyConstructible` (Table 
1006
+ [[tab:copyconstructible]]) and `CopyAssignable` (Table 
1007
+ [[tab:copyassignable]]) types. These operations shall each be of
1008
+ complexity no worse than 𝑂(\mbox{size of state}).
1009
 
1010
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
1011
 
1012
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
1013
  of type `A` is a random number engine that takes values produced by some
 
1039
  ```
1040
 
1041
  *Effects:* The base engine is initialized with `s`.
1042
 
1043
  ``` cpp
1044
+ template<class Sseq> A::A(Sseq& q);
1045
  ```
1046
 
1047
  *Effects:* The base engine is initialized with `q`.
1048
 
1049
  ``` cpp
 
1091
 
1092
  where `charT` and `traits` are constrained according to Clauses 
1093
  [[strings]] and [[input.output]].
1094
 
1095
  `D` shall satisfy the requirements of `CopyConstructible` (Table 
1096
+ [[tab:copyconstructible]]) and `CopyAssignable` (Table 
1097
+ [[tab:copyassignable]]) types.
1098
 
1099
  The sequence of numbers produced by repeated invocations of `d(g)` shall
1100
  be independent of any invocation of `os << d` or of any `const` member
1101
  function of `D` between any of the invocations `d(g)`.
1102
 
 
1110
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
1111
  `D::param_type` are in the form of `typedef`s for convenience of
1112
  exposition only.
1113
 
1114
  `P` shall satisfy the requirements of `CopyConstructible` (Table 
1115
+ [[tab:copyconstructible]]), `CopyAssignable` (Table 
1116
+ [[tab:copyassignable]]), and `EqualityComparable` (Table 
1117
+ [[tab:equalitycomparable]]) types.
1118
 
1119
  For each of the constructors of `D` taking arguments corresponding to
1120
  parameters of the distribution, `P` shall have a corresponding
1121
  constructor subject to the same requirements and taking arguments
1122
  identical in number, type, and default values. Moreover, for each of the
 
1125
  the identical name, type, and semantics.
1126
 
1127
  `P` shall have a declaration of the form
1128
 
1129
  ``` cpp
1130
+ using distribution_type = D;
1131
  ```
1132
 
1133
  ### Header `<random>` synopsis <a id="rand.synopsis">[[rand.synopsis]]</a>
1134
 
1135
  ``` cpp
1136
  #include <initializer_list>
1137
 
1138
  namespace std {
 
1139
  // [rand.eng.lcong], class template linear_congruential_engine
1140
  template<class UIntType, UIntType a, UIntType c, UIntType m>
1141
  class linear_congruential_engine;
1142
 
1143
  // [rand.eng.mers], class template mersenne_twister_engine
 
1162
  // [rand.adapt.shuf], class template shuffle_order_engine
1163
  template<class Engine, size_t k>
1164
  class shuffle_order_engine;
1165
 
1166
  // [rand.predef], engines and engine adaptors with predefined parameters
1167
+ using minstd_rand0 = see below;
1168
+ using minstd_rand = see below;
1169
+ using mt19937 = see below;
1170
+ using mt19937_64 = see below;
1171
+ using ranlux24_base = see below;
1172
+ using ranlux48_base = see below;
1173
+ using ranlux24 = see below;
1174
+ using ranlux48 = see below;
1175
+ using knuth_b = see below;
1176
+
1177
+ using default_random_engine = see below;
1178
 
1179
  // [rand.device], class random_device
1180
  class random_device;
1181
 
1182
  // [rand.util.seedseq], class seed_seq
1183
  class seed_seq;
1184
 
1185
  // [rand.util.canonical], function template generate_canonical
1186
+ template<class RealType, size_t bits, class URBG>
1187
+ RealType generate_canonical(URBG& g);
1188
 
1189
  // [rand.dist.uni.int], class template uniform_int_distribution
1190
  template<class IntType = int>
1191
  class uniform_int_distribution;
1192
 
 
1262
  class piecewise_constant_distribution;
1263
 
1264
  // [rand.dist.samp.plinear], class template piecewise_linear_distribution
1265
  template<class RealType = double>
1266
  class piecewise_linear_distribution;
1267
+ }
 
1268
  ```
1269
 
1270
  ### Random number engine class templates <a id="rand.eng">[[rand.eng]]</a>
1271
 
1272
  Each type instantiated from a class template specified in this section 
 
1277
  specified in this section  [[rand.eng]] is constant.
1278
 
1279
  Except where specified otherwise, no function described in this section 
1280
  [[rand.eng]] throws an exception.
1281
 
1282
+ Every function described in this section  [[rand.eng]] that has a
1283
+ function parameter `q` of type `Sseq&` for a template type parameter
1284
+ named `Sseq` that is different from type `seed_seq` throws what and when
1285
+ the invocation of `q.generate` throws.
1286
+
1287
  Descriptions are provided in this section  [[rand.eng]] only for engine
1288
+ operations that are not described in [[rand.req.eng]] or for operations
1289
+ where there is additional semantic information. In particular,
1290
+ declarations for copy constructors, for copy assignment operators, for
1291
+ streaming operators, and for equality and inequality operators are not
1292
+ shown in the synopses.
1293
 
1294
  Each template specified in this section  [[rand.eng]] requires one or
1295
  more relationships, involving the value(s) of its non-type template
1296
  parameter(s), to hold. A program instantiating any of these templates is
1297
  ill-formed if any such required relationship fails to hold.
1298
 
1299
  For every random number engine and for every random number engine
1300
+ adaptor `X` defined in this subclause ([[rand.eng]]) and in subclause 
1301
+ [[rand.adapt]]:
1302
 
1303
  - if the constructor
1304
  ``` cpp
1305
  template <class Sseq> explicit X(Sseq& q);
1306
  ```
 
1329
  TA(xᵢ) = (a ⋅ xᵢ + c) mod m; the generation algorithm is
1330
  GA(xᵢ) = xᵢ₊₁.
1331
 
1332
  ``` cpp
1333
  template<class UIntType, UIntType a, UIntType c, UIntType m>
1334
+ class linear_congruential_engine {
 
1335
  public:
1336
  // types
1337
+ using result_type = UIntType;
1338
 
1339
  // engine characteristics
1340
  static constexpr result_type multiplier = a;
1341
  static constexpr result_type increment = c;
1342
  static constexpr result_type modulus = m;
 
1356
  };
1357
  ```
1358
 
1359
  If the template parameter `m` is 0, the modulus m used throughout this
1360
  section  [[rand.eng.lcong]] is `numeric_limits<result_type>::max()` plus
1361
+ 1.
1362
+
1363
+ [*Note 1*: m need not be representable as a value of type
1364
+ `result_type`. — *end note*]
1365
 
1366
  If the template parameter `m` is not 0, the following relations shall
1367
  hold: `a < m` and `c < m`.
1368
 
1369
  The textual representation consists of the value of xᵢ.
 
1398
  applied to X are to be taken modulo n.
1399
 
1400
  The transition algorithm employs a twisted generalized feedback shift
1401
  register defined by shift values n and m, a twist value r, and a
1402
  conditional xor-mask a. To improve the uniformity of the result, the
1403
+ bits of the raw shift register are additionally *tempered* (i.e.,
1404
  scrambled) according to a bit-scrambling matrix defined by values
1405
  u, d, s, b, t, c, and ℓ.
1406
 
1407
  The state transition is performed as follows:
1408
 
 
1415
  ``` cpp
1416
  template<class UIntType, size_t w, size_t n, size_t m, size_t r,
1417
  UIntType a, size_t u, UIntType d, size_t s,
1418
  UIntType b, size_t t,
1419
  UIntType c, size_t l, UIntType f>
1420
+ class mersenne_twister_engine {
 
1421
  public:
1422
  // types
1423
+ using result_type = UIntType;
1424
 
1425
  // engine characteristics
1426
  static constexpr size_t word_size = w;
1427
  static constexpr size_t state_size = n;
1428
  static constexpr size_t shift_size = m;
 
1499
  additionally consists of an integer c (known as the *carry*) whose value
1500
  is either 0 or 1.
1501
 
1502
  The state transition is performed as follows:
1503
 
1504
+ [*Note 1*: This algorithm corresponds to a modular linear function of
1505
+ the form TA(xᵢ) = (a ⋅ xᵢ) mod b, where b is of the form mʳ - mˢ + 1
1506
+ and a = b - (b-1) / m. — *end note*]
1507
 
1508
  The generation algorithm is given by GA(xᵢ) = y, where y is the value
1509
  produced as a result of advancing the engine’s state as described above.
1510
 
1511
  ``` cpp
1512
  template<class UIntType, size_t w, size_t s, size_t r>
1513
+ class subtract_with_carry_engine {
 
1514
  public:
1515
  // types
1516
+ using result_type = UIntType;
1517
 
1518
  // engine characteristics
1519
  static constexpr size_t word_size = w;
1520
  static constexpr size_t short_lag = s;
1521
  static constexpr size_t long_lag = r;
 
1577
  ### Random number engine adaptor class templates <a id="rand.adapt">[[rand.adapt]]</a>
1578
 
1579
  #### In general <a id="rand.adapt.general">[[rand.adapt.general]]</a>
1580
 
1581
  Each type instantiated from a class template specified in this section 
1582
+ [[rand.adapt]] satisfies the requirements of a random number engine
1583
  adaptor ([[rand.req.adapt]]) type.
1584
 
1585
  Except where specified otherwise, the complexity of each function
1586
  specified in this section  [[rand.adapt]] is constant.
1587
 
1588
  Except where specified otherwise, no function described in this section 
1589
  [[rand.adapt]] throws an exception.
1590
 
1591
+ Every function described in this section  [[rand.adapt]] that has a
1592
+ function parameter `q` of type `Sseq&` for a template type parameter
1593
+ named `Sseq` that is different from type `seed_seq` throws what and when
1594
+ the invocation of `q.generate` throws.
1595
+
1596
  Descriptions are provided in this section  [[rand.adapt]] only for
1597
  adaptor operations that are not described in section  [[rand.req.adapt]]
1598
  or for operations where there is additional semantic information. In
1599
  particular, declarations for copy constructors, for copy assignment
1600
  operators, for streaming operators, and for equality and inequality
 
1622
  The generation algorithm yields the value returned by the last
1623
  invocation of `e()` while advancing `e`’s state as described above.
1624
 
1625
  ``` cpp
1626
  template<class Engine, size_t p, size_t r>
1627
+ class discard_block_engine {
 
1628
  public:
1629
  // types
1630
+ using result_type = typename Engine::result_type;
1631
 
1632
  // engine characteristics
1633
  static constexpr size_t block_size = p;
1634
  static constexpr size_t used_block = r;
1635
  static constexpr result_type min() { return Engine::min(); }
 
1676
  e’s state.
1677
 
1678
  The transition and generation algorithms are described in terms of the
1679
  following integral constants:
1680
 
1681
+ [*Note 1*: The relation w = n₀ w₀ + (n - n₀)(w₀ + 1) always
1682
+ holds. — *end note*]
1683
 
1684
  The transition algorithm is carried out by invoking `e()` as often as
1685
  needed to obtain n₀ values less than y₀ + `e.min()` and n - n₀ values
1686
  less than y₁ + `e.min()` .
1687
 
 
1701
  }
1702
  ```
1703
 
1704
  ``` cpp
1705
  template<class Engine, size_t w, class UIntType>
1706
+ class independent_bits_engine {
 
1707
  public:
1708
  // types
1709
+ using result_type = UIntType;
1710
 
1711
  // engine characteristics
1712
  static constexpr result_type min() { return 0; }
1713
  static constexpr result_type max() { return 2^w - 1; }
1714
 
 
1756
  The generation algorithm yields the last value of `Y` produced while
1757
  advancing `e`’s state as described above.
1758
 
1759
  ``` cpp
1760
  template<class Engine, size_t k>
1761
+ class shuffle_order_engine {
 
1762
  public:
1763
  // types
1764
+ using result_type = typename Engine::result_type;
1765
 
1766
  // engine characteristics
1767
  static constexpr size_t table_size = k;
1768
  static constexpr result_type min() { return Engine::min(); }
1769
  static constexpr result_type max() { return Engine::max(); }
 
1785
  // property functions
1786
  const Engine& base() const noexcept { return e; };
1787
 
1788
  private:
1789
  Engine e; // exposition only
 
1790
  result_type V[k]; // exposition only
1791
+ result_type Y; // exposition only
1792
  };
1793
  ```
1794
 
1795
  The following relation shall hold: `0 < k`.
1796
 
 
1803
  successive invocations of `e()`.
1804
 
1805
  ### Engines and engine adaptors with predefined parameters <a id="rand.predef">[[rand.predef]]</a>
1806
 
1807
  ``` cpp
1808
+ using minstd_rand0 =
1809
+ linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>;
1810
  ```
1811
 
1812
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1813
  default-constructed object of type `minstd_rand0` shall produce the
1814
  value 1043618065.
1815
 
1816
  ``` cpp
1817
+ using minstd_rand =
1818
+ linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>;
1819
  ```
1820
 
1821
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1822
  default-constructed object of type `minstd_rand` shall produce the value
1823
  399268537.
1824
 
1825
  ``` cpp
1826
+ using mt19937 =
1827
+ mersenne_twister_engine<uint_fast32_t,
1828
+ 32,624,397,31,0x9908b0df,11,0xffffffff,7,0x9d2c5680,15,0xefc60000,18,1812433253>;
1829
  ```
1830
 
1831
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1832
  default-constructed object of type `mt19937` shall produce the value
1833
  4123659995.
1834
 
1835
  ``` cpp
1836
+ using mt19937_64 =
1837
+ mersenne_twister_engine<uint_fast64_t,
1838
  64,312,156,31,0xb5026f5aa96619e9,29,
1839
  0x5555555555555555,17,
1840
  0x71d67fffeda60000,37,
1841
  0xfff7eee000000000,43,
1842
+ 6364136223846793005>;
 
1843
  ```
1844
 
1845
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1846
  default-constructed object of type `mt19937_64` shall produce the value
1847
  9981545732273789042.
1848
 
1849
  ``` cpp
1850
+ using ranlux24_base =
1851
+ subtract_with_carry_engine<uint_fast32_t, 24, 10, 24>;
1852
  ```
1853
 
1854
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1855
  default-constructed object of type `ranlux24_base` shall produce the
1856
  value 7937952.
1857
 
1858
  ``` cpp
1859
+ using ranlux48_base =
1860
+ subtract_with_carry_engine<uint_fast64_t, 48, 5, 12>;
1861
  ```
1862
 
1863
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1864
  default-constructed object of type `ranlux48_base` shall produce the
1865
  value 61839128582725.
1866
 
1867
  ``` cpp
1868
+ using ranlux24 = discard_block_engine<ranlux24_base, 223, 23>;
 
1869
  ```
1870
 
1871
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1872
  default-constructed object of type `ranlux24` shall produce the value
1873
  9901578.
1874
 
1875
  ``` cpp
1876
+ using ranlux48 = discard_block_engine<ranlux48_base, 389, 11>;
 
1877
  ```
1878
 
1879
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1880
  default-constructed object of type `ranlux48` shall produce the value
1881
  249142670248501.
1882
 
1883
  ``` cpp
1884
+ using knuth_b = shuffle_order_engine<minstd_rand0,256>;
 
1885
  ```
1886
 
1887
  *Required behavior:* The $10000^{\,th}$ consecutive invocation of a
1888
  default-constructed object of type `knuth_b` shall produce the value
1889
  1112339016.
1890
 
1891
  ``` cpp
1892
+ using default_random_engine = implementation-defined;
 
1893
  ```
1894
 
1895
+ *Remarks:* The choice of engine type named by this `typedef` is
1896
+ *implementation-defined*.
1897
+
1898
+ [*Note 1*: The implementation may select this type on the basis of
1899
+ performance, size, quality, or any combination of such factors, so as to
1900
+ provide at least acceptable engine behavior for relatively casual,
1901
+ inexpert, and/or lightweight use. Because different implementations may
1902
+ select different underlying engine types, code that uses this `typedef`
1903
+ need not generate identical sequences across
1904
+ implementations. — *end note*]
1905
 
1906
  ### Class `random_device` <a id="rand.device">[[rand.device]]</a>
1907
 
1908
+ A `random_device` uniform random bit generator produces nondeterministic
1909
+ random numbers.
1910
 
1911
+ If implementation limitations prevent generating nondeterministic random
1912
+ numbers, the implementation may employ a random number engine.
1913
 
1914
  ``` cpp
1915
+ class random_device {
 
1916
  public:
1917
  // types
1918
+ using result_type = unsigned int;
1919
 
1920
  // generator characteristics
1921
  static constexpr result_type min() { return numeric_limits<result_type>::min(); }
1922
  static constexpr result_type max() { return numeric_limits<result_type>::max(); }
1923
 
 
1938
 
1939
  ``` cpp
1940
  explicit random_device(const string& token = implementation-defined);
1941
  ```
1942
 
1943
+ *Effects:* Constructs a `random_device` nondeterministic uniform random
1944
+ bit generator object. The semantics and default value of the `token`
1945
+ parameter are *implementation-defined*. [^3]
1946
 
1947
+ *Throws:* A value of an *implementation-defined* type derived from
1948
  `exception` if the `random_device` could not be initialized.
1949
 
1950
  ``` cpp
1951
  double entropy() const noexcept;
1952
  ```
 
1957
 
1958
  ``` cpp
1959
  result_type operator()();
1960
  ```
1961
 
1962
+ *Returns:* A nondeterministic random value, uniformly distributed
1963
+ between `min()` and `max()`, inclusive. It is *implementation-defined*
1964
+ how these values are generated.
1965
 
1966
+ *Throws:* A value of an *implementation-defined* type derived from
1967
  `exception` if a random number could not be obtained.
1968
 
1969
  ### Utilities <a id="rand.util">[[rand.util]]</a>
1970
 
1971
  #### Class `seed_seq` <a id="rand.util.seedseq">[[rand.util.seedseq]]</a>
1972
 
1973
  ``` cpp
1974
+ class seed_seq {
 
1975
  public:
1976
  // types
1977
+ using result_type = uint_least32_t;
1978
 
1979
  // constructors
1980
  seed_seq();
1981
  template<class T>
1982
  seed_seq(initializer_list<T> il);
 
1986
  // generating functions
1987
  template<class RandomAccessIterator>
1988
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
1989
 
1990
  // property functions
1991
+ size_t size() const noexcept;
1992
  template<class OutputIterator>
1993
  void param(OutputIterator dest) const;
1994
 
1995
  // no copy functions
1996
  seed_seq(const seed_seq& ) = delete;
 
2040
  template<class RandomAccessIterator>
2041
  void generate(RandomAccessIterator begin, RandomAccessIterator end);
2042
  ```
2043
 
2044
  *Requires:* `RandomAccessIterator` shall meet the requirements of a
2045
+ mutable random access iterator ([[random.access.iterators]]). Moreover,
 
2046
  `iterator_traits<RandomAccessIterator>::value_type` shall denote an
2047
  unsigned integer type capable of accommodating 32-bit quantities.
2048
 
2049
  *Effects:* Does nothing if `begin == end`. Otherwise, with
2050
  s = `v.size()` and n = `end` - `begin`, fills the supplied range
 
2055
 
2056
  *Throws:* What and when `RandomAccessIterator` operations of `begin` and
2057
  `end` throw.
2058
 
2059
  ``` cpp
2060
+ size_t size() const noexcept;
2061
  ```
2062
 
2063
  *Returns:* The number of 32-bit units that would be returned by a call
2064
  to `param()`.
2065
 
 
 
2066
  *Complexity:* Constant time.
2067
 
2068
  ``` cpp
2069
  template<class OutputIterator>
2070
  void param(OutputIterator dest) const;
2071
  ```
2072
 
2073
  *Requires:* `OutputIterator` shall satisfy the requirements of an output
2074
+ iterator ([[output.iterators]]). Moreover, the expression `*dest = rt`
2075
+ shall be valid for a value `rt` of type `result_type`.
 
2076
 
2077
  *Effects:* Copies the sequence of prepared 32-bit units to the given
2078
  destination, as if by executing the following statement:
2079
 
2080
  ``` cpp
 
2085
 
2086
  #### Function template `generate_canonical` <a id="rand.util.canonical">[[rand.util.canonical]]</a>
2087
 
2088
  Each function instantiated from the template described in this section 
2089
  [[rand.util.canonical]] maps the result of one or more invocations of a
2090
+ supplied uniform random bit generator `g` to one member of the specified
2091
+ `RealType` such that, if the values gᵢ produced by `g` are uniformly
2092
+ distributed, the instantiation’s results tⱼ, 0 ≤ tⱼ < 1, are distributed
2093
+ as uniformly as possible as specified below.
2094
 
2095
+ [*Note 1*: Obtaining a value in this way can be a useful step in the
2096
+ process of transforming a value generated by a uniform random bit
2097
+ generator into a value that can be delivered by a random number
2098
+ distribution. — *end note*]
2099
 
2100
  ``` cpp
2101
+ template<class RealType, size_t bits, class URBG>
2102
+ RealType generate_canonical(URBG& g);
2103
  ```
2104
 
2105
  *Complexity:* Exactly k = max(1, ⌈ b / log₂ R ⌉) invocations of `g`,
2106
  where b[^5] is the lesser of `numeric_limits<RealType>::digits` and
2107
  `bits`, and R is the value of `g.max()` - `g.min()` + 1.
 
2129
  particular, declarations for copy constructors, for copy assignment
2130
  operators, for streaming operators, and for equality and inequality
2131
  operators are not shown in the synopses.
2132
 
2133
  The algorithms for producing each of the specified distributions are
2134
+ *implementation-defined*.
2135
 
2136
  The value of each probability density function p(z) and of each discrete
2137
  probability function P(zᵢ) specified in this section is 0 everywhere
2138
  outside its stated domain.
2139
 
 
2147
  P(i\,|\,a,b) = 1 / (b - a + 1)
2148
  \; \mbox{.}$$
2149
 
2150
  ``` cpp
2151
  template<class IntType = int>
2152
+ class uniform_int_distribution {
 
2153
  public:
2154
  // types
2155
+ using result_type = IntType;
2156
+ using param_type = unspecified;
2157
 
2158
  // constructors and reset functions
2159
  explicit uniform_int_distribution(IntType a = 0, IntType b = numeric_limits<IntType>::max());
2160
  explicit uniform_int_distribution(const param_type& parm);
2161
  void reset();
2162
 
2163
  // generating functions
2164
+ template<class URBG>
2165
+ result_type operator()(URBG& g);
2166
+ template<class URBG>
2167
+ result_type operator()(URBG& g, const param_type& parm);
2168
 
2169
  // property functions
2170
  result_type a() const;
2171
  result_type b() const;
2172
  param_type param() const;
 
2205
  numbers x, a ≤ x < b, distributed according to the constant probability
2206
  density function $$%
2207
  p(x\,|\,a,b) = 1 / (b - a)
2208
  \; \mbox{.}$$
2209
 
2210
+ [*Note 1*: This implies that p(x | a,b) is undefined when
2211
+ `a == b`. — *end note*]
2212
+
2213
  ``` cpp
2214
  template<class RealType = double>
2215
+ class uniform_real_distribution {
 
2216
  public:
2217
  // types
2218
+ using result_type = RealType;
2219
+ using param_type = unspecified;
2220
 
2221
  // constructors and reset functions
2222
  explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
2223
  explicit uniform_real_distribution(const param_type& parm);
2224
  void reset();
2225
 
2226
  // generating functions
2227
+ template<class URBG>
2228
+ result_type operator()(URBG& g);
2229
+ template<class URBG>
2230
+ result_type operator()(URBG& g, const param_type& parm);
2231
 
2232
  // property functions
2233
  result_type a() const;
2234
  result_type b() const;
2235
  param_type param() const;
 
2274
  1-p & \mbox{if} & b = \tcode{false}
2275
  \end{array}\right.
2276
  \; \mbox{.}$$
2277
 
2278
  ``` cpp
2279
+ class bernoulli_distribution {
 
2280
  public:
2281
  // types
2282
+ using result_type = bool;
2283
+ using param_type = unspecified;
2284
 
2285
  // constructors and reset functions
2286
  explicit bernoulli_distribution(double p = 0.5);
2287
  explicit bernoulli_distribution(const param_type& parm);
2288
  void reset();
2289
 
2290
  // generating functions
2291
+ template<class URBG>
2292
+ result_type operator()(URBG& g);
2293
+ template<class URBG>
2294
+ result_type operator()(URBG& g, const param_type& parm);
2295
 
2296
  // property functions
2297
  double p() const;
2298
  param_type param() const;
2299
  void param(const param_type& parm);
 
2327
  = \binom{t}{i} \cdot p^i \cdot (1-p)^{t-i}
2328
  \; \mbox{.}$$
2329
 
2330
  ``` cpp
2331
  template<class IntType = int>
2332
+ class binomial_distribution {
 
2333
  public:
2334
  // types
2335
+ using result_type = IntType;
2336
+ using param_type = unspecified;
2337
 
2338
  // constructors and reset functions
2339
  explicit binomial_distribution(IntType t = 1, double p = 0.5);
2340
  explicit binomial_distribution(const param_type& parm);
2341
  void reset();
2342
 
2343
  // generating functions
2344
+ template<class URBG>
2345
+ result_type operator()(URBG& g);
2346
+ template<class URBG>
2347
+ result_type operator()(URBG& g, const param_type& parm);
2348
 
2349
  // property functions
2350
  IntType t() const;
2351
  double p() const;
2352
  param_type param() const;
 
2388
  = p \cdot (1-p)^{i}
2389
  \; \mbox{.}$$
2390
 
2391
  ``` cpp
2392
  template<class IntType = int>
2393
+ class geometric_distribution {
 
2394
  public:
2395
  // types
2396
+ using result_type = IntType;
2397
+ using param_type = unspecified;
2398
 
2399
  // constructors and reset functions
2400
  explicit geometric_distribution(double p = 0.5);
2401
  explicit geometric_distribution(const param_type& parm);
2402
  void reset();
2403
 
2404
  // generating functions
2405
+ template<class URBG>
2406
+ result_type operator()(URBG& g);
2407
+ template<class URBG>
2408
+ result_type operator()(URBG& g, const param_type& parm);
2409
 
2410
  // property functions
2411
  double p() const;
2412
  param_type param() const;
2413
  void param(const param_type& parm);
 
2439
  function $$%
2440
  P(i\,|\,k,p)
2441
  = \binom{k+i-1}{i} \cdot p^k \cdot (1-p)^i
2442
  \; \mbox{.}$$
2443
 
2444
+ [*Note 1*: This implies that P(i | k,p) is undefined when
2445
+ `p == 1`. — *end note*]
2446
+
2447
  ``` cpp
2448
  template<class IntType = int>
2449
+ class negative_binomial_distribution {
 
2450
  public:
2451
  // types
2452
+ using result_type = IntType;
2453
+ using param_type = unspecified;
2454
 
2455
  // constructor and reset functions
2456
  explicit negative_binomial_distribution(IntType k = 1, double p = 0.5);
2457
  explicit negative_binomial_distribution(const param_type& parm);
2458
  void reset();
2459
 
2460
  // generating functions
2461
+ template<class URBG>
2462
+ result_type operator()(URBG& g);
2463
+ template<class URBG>
2464
+ result_type operator()(URBG& g, const param_type& parm);
2465
 
2466
  // property functions
2467
  IntType k() const;
2468
  double p() const;
2469
  param_type param() const;
 
2513
  template<class IntType = int>
2514
  class poisson_distribution
2515
  {
2516
  public:
2517
  // types
2518
+ using result_type = IntType;
2519
+ using param_type = unspecified;
2520
 
2521
  // constructors and reset functions
2522
  explicit poisson_distribution(double mean = 1.0);
2523
  explicit poisson_distribution(const param_type& parm);
2524
  void reset();
2525
 
2526
  // generating functions
2527
+ template<class URBG>
2528
+ result_type operator()(URBG& g);
2529
+ template<class URBG>
2530
+ result_type operator()(URBG& g, const param_type& parm);
2531
 
2532
  // property functions
2533
  double mean() const;
2534
  param_type param() const;
2535
  void param(const param_type& parm);
 
2563
  = \lambda e^{-\lambda x}
2564
  \; \mbox{.}$$
2565
 
2566
  ``` cpp
2567
  template<class RealType = double>
2568
+ class exponential_distribution {
 
2569
  public:
2570
  // types
2571
+ using result_type = RealType;
2572
+ using param_type = unspecified;
2573
 
2574
  // constructors and reset functions
2575
  explicit exponential_distribution(RealType lambda = 1.0);
2576
  explicit exponential_distribution(const param_type& parm);
2577
  void reset();
2578
 
2579
  // generating functions
2580
+ template<class URBG>
2581
+ result_type operator()(URBG& g);
2582
+ template<class URBG>
2583
+ result_type operator()(URBG& g, const param_type& parm);
2584
 
2585
  // property functions
2586
  RealType lambda() const;
2587
  param_type param() const;
2588
  void param(const param_type& parm);
 
2595
  explicit exponential_distribution(RealType lambda = 1.0);
2596
  ```
2597
 
2598
  *Requires:* 0 < `lambda`.
2599
 
2600
+ *Effects:* Constructs an `exponential_distribution` object; `lambda`
2601
  corresponds to the parameter of the distribution.
2602
 
2603
  ``` cpp
2604
  RealType lambda() const;
2605
  ```
 
2617
  \, \cdot \, x^{\, \alpha-1}
2618
  \; \mbox{.}$$
2619
 
2620
  ``` cpp
2621
  template<class RealType = double>
2622
+ class gamma_distribution {
 
2623
  public:
2624
  // types
2625
+ using result_type = RealType;
2626
+ using param_type = unspecified;
2627
 
2628
  // constructors and reset functions
2629
  explicit gamma_distribution(RealType alpha = 1.0, RealType beta = 1.0);
2630
  explicit gamma_distribution(const param_type& parm);
2631
  void reset();
2632
 
2633
  // generating functions
2634
+ template<class URBG>
2635
+ result_type operator()(URBG& g);
2636
+ template<class URBG>
2637
+ result_type operator()(URBG& g, const param_type& parm);
2638
 
2639
  // property functions
2640
  RealType alpha() const;
2641
  RealType beta() const;
2642
  param_type param() const;
 
2680
  \cdot \, \exp\left( -\left(\frac{x}{b}\right)^a\right)
2681
  \; \mbox{.}$$
2682
 
2683
  ``` cpp
2684
  template<class RealType = double>
2685
+ class weibull_distribution {
 
2686
  public:
2687
  // types
2688
+ using result_type = RealType;
2689
+ using param_type = unspecified;
2690
 
2691
  // constructor and reset functions
2692
  explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0);
2693
  explicit weibull_distribution(const param_type& parm);
2694
  void reset();
2695
 
2696
  // generating functions
2697
+ template<class URBG>
2698
+ result_type operator()(URBG& g);
2699
+ template<class URBG>
2700
+ result_type operator()(URBG& g, const param_type& parm);
2701
 
2702
  // property functions
2703
  RealType a() const;
2704
  RealType b() const;
2705
  param_type param() const;
 
2744
  \right)
2745
  \; \mbox{.}$$
2746
 
2747
  ``` cpp
2748
  template<class RealType = double>
2749
+ class extreme_value_distribution {
 
2750
  public:
2751
  // types
2752
+ using result_type = RealType;
2753
+ using param_type = unspecified;
2754
 
2755
  // constructor and reset functions
2756
  explicit extreme_value_distribution(RealType a = 0.0, RealType b = 1.0);
2757
  explicit extreme_value_distribution(const param_type& parm);
2758
  void reset();
2759
 
2760
  // generating functions
2761
+ template<class URBG>
2762
+ result_type operator()(URBG& g);
2763
+ template<class URBG>
2764
+ result_type operator()(URBG& g, const param_type& parm);
2765
 
2766
  // property functions
2767
  RealType a() const;
2768
  RealType b() const;
2769
  param_type param() const;
 
2813
  \; \mbox{.}$$ The distribution parameters μ and σ are also known as this
2814
  distribution’s *mean* and *standard deviation* .
2815
 
2816
  ``` cpp
2817
  template<class RealType = double>
2818
+ class normal_distribution {
 
2819
  public:
2820
  // types
2821
+ using result_type = RealType;
2822
+ using param_type = unspecified;
2823
 
2824
  // constructors and reset functions
2825
  explicit normal_distribution(RealType mean = 0.0, RealType stddev = 1.0);
2826
  explicit normal_distribution(const param_type& parm);
2827
  void reset();
2828
 
2829
  // generating functions
2830
+ template<class URBG>
2831
+ result_type operator()(URBG& g);
2832
+ template<class URBG>
2833
+ result_type operator()(URBG& g, const param_type& parm);
2834
 
2835
  // property functions
2836
  RealType mean() const;
2837
  RealType stddev() const;
2838
  param_type param() const;
 
2880
  }
2881
  \; \mbox{.}$$
2882
 
2883
  ``` cpp
2884
  template<class RealType = double>
2885
+ class lognormal_distribution {
 
2886
  public:
2887
  // types
2888
+ using result_type = RealType;
2889
+ using param_type = unspecified;
2890
 
2891
  // constructor and reset functions
2892
  explicit lognormal_distribution(RealType m = 0.0, RealType s = 1.0);
2893
  explicit lognormal_distribution(const param_type& parm);
2894
  void reset();
2895
 
2896
  // generating functions
2897
+ template<class URBG>
2898
+ result_type operator()(URBG& g);
2899
+ template<class URBG>
2900
+ result_type operator()(URBG& g, const param_type& parm);
2901
 
2902
  // property functions
2903
  RealType m() const;
2904
  RealType s() const;
2905
  param_type param() const;
 
2942
  {\Gamma(n/2) \cdot 2^{n/2}}
2943
  \; \mbox{.}$$
2944
 
2945
  ``` cpp
2946
  template<class RealType = double>
2947
+ class chi_squared_distribution {
 
2948
  public:
2949
  // types
2950
+ using result_type = RealType;
2951
+ using param_type = unspecified;
2952
 
2953
  // constructor and reset functions
2954
  explicit chi_squared_distribution(RealType n = 1);
2955
  explicit chi_squared_distribution(const param_type& parm);
2956
  void reset();
2957
 
2958
  // generating functions
2959
+ template<class URBG>
2960
+ result_type operator()(URBG& g);
2961
+ template<class URBG>
2962
+ result_type operator()(URBG& g, const param_type& parm);
2963
 
2964
  // property functions
2965
  RealType n() const;
2966
  param_type param() const;
2967
  void param(const param_type& parm);
 
2994
  = \left( \pi b \left( 1 + \left( \frac{x-a}{b} \right)^2 \;\right)\right)^{-1}
2995
  \; \mbox{.}$$
2996
 
2997
  ``` cpp
2998
  template<class RealType = double>
2999
+ class cauchy_distribution {
 
3000
  public:
3001
  // types
3002
+ using result_type = RealType;
3003
+ using param_type = unspecified;
3004
 
3005
  // constructor and reset functions
3006
  explicit cauchy_distribution(RealType a = 0.0, RealType b = 1.0);
3007
  explicit cauchy_distribution(const param_type& parm);
3008
  void reset();
3009
 
3010
  // generating functions
3011
+ template<class URBG>
3012
+ result_type operator()(URBG& g);
3013
+ template<class URBG>
3014
+ result_type operator()(URBG& g, const param_type& parm);
3015
 
3016
  // property functions
3017
  RealType a() const;
3018
  RealType b() const;
3019
  param_type param() const;
 
3062
  {\left( 1 + \frac{m x}{n} \right)}^{-(m+n)/2}
3063
  \; \mbox{.}$$
3064
 
3065
  ``` cpp
3066
  template<class RealType = double>
3067
+ class fisher_f_distribution {
 
3068
  public:
3069
  // types
3070
+ using result_type = RealType;
3071
+ using param_type = unspecified;
3072
 
3073
  // constructor and reset functions
3074
  explicit fisher_f_distribution(RealType m = 1, RealType n = 1);
3075
  explicit fisher_f_distribution(const param_type& parm);
3076
  void reset();
3077
 
3078
  // generating functions
3079
+ template<class URBG>
3080
+ result_type operator()(URBG& g);
3081
+ template<class URBG>
3082
+ result_type operator()(URBG& g, const param_type& parm);
3083
 
3084
  // property functions
3085
  RealType m() const;
3086
  RealType n() const;
3087
  param_type param() const;
 
3126
  \cdot \left( 1+\frac{x^2}{n} \right) ^ {-(n+1)/2}
3127
  \; \mbox{.}$$
3128
 
3129
  ``` cpp
3130
  template<class RealType = double>
3131
+ class student_t_distribution {
 
3132
  public:
3133
  // types
3134
+ using result_type = RealType;
3135
+ using param_type = unspecified;
3136
 
3137
  // constructor and reset functions
3138
  explicit student_t_distribution(RealType n = 1);
3139
  explicit student_t_distribution(const param_type& parm);
3140
  void reset();
3141
 
3142
  // generating functions
3143
+ template<class URBG>
3144
+ result_type operator()(URBG& g);
3145
+ template<class URBG>
3146
+ result_type operator()(URBG& g, const param_type& parm);
3147
 
3148
  // property functions
3149
  RealType n() const;
3150
  param_type param() const;
3151
  void param(const param_type& parm);
 
3187
  non-NaN, and non-infinity. Moreover, the following relation shall hold:
3188
  0 < S = w₀ + ⋯ + wₙ₋₁.
3189
 
3190
  ``` cpp
3191
  template<class IntType = int>
3192
+ class discrete_distribution {
 
3193
  public:
3194
  // types
3195
+ using result_type = IntType;
3196
+ using param_type = unspecified;
3197
 
3198
  // constructor and reset functions
3199
  discrete_distribution();
3200
  template<class InputIterator>
3201
  discrete_distribution(InputIterator firstW, InputIterator lastW);
 
3204
  discrete_distribution(size_t nw, double xmin, double xmax, UnaryOperation fw);
3205
  explicit discrete_distribution(const param_type& parm);
3206
  void reset();
3207
 
3208
  // generating functions
3209
+ template<class URBG>
3210
+ result_type operator()(URBG& g);
3211
+ template<class URBG>
3212
+ result_type operator()(URBG& g, const param_type& parm);
3213
 
3214
  // property functions
3215
  vector<double> probabilities() const;
3216
  param_type param() const;
3217
  void param(const param_type& parm);
 
3223
  ``` cpp
3224
  discrete_distribution();
3225
  ```
3226
 
3227
  *Effects:* Constructs a `discrete_distribution` object with n = 1 and
3228
+ p₀ = 1.
3229
+
3230
+ [*Note 1*: Such an object will always deliver the value
3231
+ 0. — *end note*]
3232
 
3233
  ``` cpp
3234
  template<class InputIterator>
3235
  discrete_distribution(InputIterator firstW, InputIterator lastW);
3236
  ```
3237
 
3238
  *Requires:* `InputIterator` shall satisfy the requirements of an input
3239
+ iterator ([[input.iterators]]). Moreover,
3240
  `iterator_traits<InputIterator>::value_type` shall denote a type that is
3241
  convertible to `double`. If `firstW == lastW`, let n = 1 and w₀ = 1.
3242
  Otherwise, [`firstW`, `lastW`) shall form a sequence w of length n > 0.
3243
 
3244
  *Effects:* Constructs a `discrete_distribution` object with
 
3299
  non-infinity. Moreover, the following relation shall hold:
3300
  0 < S = w₀ + ⋯ + wₙ₋₁.
3301
 
3302
  ``` cpp
3303
  template<class RealType = double>
3304
+ class piecewise_constant_distribution {
 
3305
  public:
3306
  // types
3307
+ using result_type = RealType;
3308
+ using param_type = unspecified;
3309
 
3310
  // constructor and reset functions
3311
  piecewise_constant_distribution();
3312
  template<class InputIteratorB, class InputIteratorW>
3313
  piecewise_constant_distribution(InputIteratorB firstB, InputIteratorB lastB,
3314
  InputIteratorW firstW);
3315
  template<class UnaryOperation>
3316
  piecewise_constant_distribution(initializer_list<RealType> bl, UnaryOperation fw);
3317
  template<class UnaryOperation>
3318
+ piecewise_constant_distribution(size_t nw, RealType xmin, RealType xmax,
3319
+ UnaryOperation fw);
3320
  explicit piecewise_constant_distribution(const param_type& parm);
3321
  void reset();
3322
 
3323
  // generating functions
3324
+ template<class URBG>
3325
+ result_type operator()(URBG& g);
3326
+ template<class URBG>
3327
+ result_type operator()(URBG& g, const param_type& parm);
3328
 
3329
  // property functions
3330
  vector<result_type> intervals() const;
3331
  vector<result_type> densities() const;
3332
  param_type param() const;
 
3439
  \cdot \sum_{k=0}^{n-1} (w_k + w_{k+1}) \cdot (b_{k+1} - b_k)
3440
  \; \mbox{.}$$
3441
 
3442
  ``` cpp
3443
  template<class RealType = double>
3444
+ class piecewise_linear_distribution {
 
3445
  public:
3446
  // types
3447
+ using result_type = RealType;
3448
+ using param_type = unspecified;
3449
 
3450
  // constructor and reset functions
3451
  piecewise_linear_distribution();
3452
  template<class InputIteratorB, class InputIteratorW>
3453
  piecewise_linear_distribution(InputIteratorB firstB, InputIteratorB lastB,
 
3458
  piecewise_linear_distribution(size_t nw, RealType xmin, RealType xmax, UnaryOperation fw);
3459
  explicit piecewise_linear_distribution(const param_type& parm);
3460
  void reset();
3461
 
3462
  // generating functions
3463
+ template<class URBG>
3464
+ result_type operator()(URBG& g);
3465
+ template<class URBG>
3466
+ result_type operator()(URBG& g, const param_type& parm);
3467
 
3468
  // property functions
3469
  vector<result_type> intervals() const;
3470
  vector<result_type> densities() const;
3471
  param_type param() const;
 
3551
 
3552
  *Returns:* A `vector<result_type>` whose `size` member returns n and
3553
  whose `operator[]` member returns ρₖ when invoked with argument k for
3554
  k = 0, …, n.
3555
 
3556
+ ### Low-quality random number generation <a id="c.math.rand">[[c.math.rand]]</a>
3557
+
3558
+ [*Note 1*: The header `<cstdlib>` ([[cstdlib.syn]]) declares the
3559
+ functions described in this subclause. — *end note*]
3560
+
3561
+ ``` cpp
3562
+ int rand();
3563
+ void srand(unsigned int seed);
3564
+ ```
3565
+
3566
+ *Effects:* The `rand` and `srand` functions have the semantics specified
3567
+ in the C standard library.
3568
+
3569
+ *Remarks:* The implementation may specify that particular library
3570
+ functions may call `rand`. It is *implementation-defined* whether the
3571
+ `rand` function may introduce data races ([[res.on.data.races]]).
3572
+
3573
+ [*Note 1*: The other random number generation facilities in this
3574
+ International Standard ([[rand]]) are often preferable to `rand`,
3575
+ because `rand`’s underlying algorithm is unspecified. Use of `rand`
3576
+ therefore continues to be non-portable, with unpredictable and
3577
+ oft-questionable quality and performance. — *end note*]
3578
+
3579
+ ISO C 7.22.2
3580
+
3581
  ## Numeric arrays <a id="numarray">[[numarray]]</a>
3582
 
3583
  ### Header `<valarray>` synopsis <a id="valarray.syn">[[valarray.syn]]</a>
3584
 
3585
  ``` cpp
3586
  #include <initializer_list>
3587
 
3588
  namespace std {
 
3589
  template<class T> class valarray; // An array of type T
3590
  class slice; // a BLAS-like slice out of an array
3591
  template<class T> class slice_array;
3592
  class gslice; // a generalized slice out of an array
3593
  template<class T> class gslice_array;
 
3726
  identical functions taking every combination of `const valarray<T>&`
3727
  and replacement types shall be added.
3728
 
3729
  In particular, an implementation shall allow a `valarray<T>` to be
3730
  constructed from such replacement types and shall allow assignments and
3731
+ compound assignments of such types to `valarray<T>`, `slice_array<T>`,
3732
  `gslice_array<T>`, `mask_array<T>` and `indirect_array<T>` objects.
3733
 
3734
  These library functions are permitted to throw a `bad_alloc` (
3735
  [[bad.alloc]]) exception if there are not sufficient resources available
3736
  to carry out the operation. Note that the exception is not mandated.
 
3741
 
3742
  ``` cpp
3743
  namespace std {
3744
  template<class T> class valarray {
3745
  public:
3746
+ using value_type = T;
3747
 
3748
+ // [valarray.cons], construct/destroy
3749
  valarray();
3750
  explicit valarray(size_t);
3751
  valarray(const T&, size_t);
3752
  valarray(const T*, size_t);
3753
  valarray(const valarray&);
 
3757
  valarray(const mask_array<T>&);
3758
  valarray(const indirect_array<T>&);
3759
  valarray(initializer_list<T>);
3760
  ~valarray();
3761
 
3762
+ // [valarray.assign], assignment
3763
+ valarray& operator=(const valarray&);
3764
+ valarray& operator=(valarray&&) noexcept;
3765
  valarray& operator=(initializer_list<T>);
3766
+ valarray& operator=(const T&);
3767
+ valarray& operator=(const slice_array<T>&);
3768
+ valarray& operator=(const gslice_array<T>&);
3769
+ valarray& operator=(const mask_array<T>&);
3770
+ valarray& operator=(const indirect_array<T>&);
3771
 
3772
+ // [valarray.access], element access
3773
  const T& operator[](size_t) const;
3774
  T& operator[](size_t);
3775
 
3776
+ // [valarray.sub], subset operations
3777
+ valarray operator[](slice) const;
3778
  slice_array<T> operator[](slice);
3779
+ valarray operator[](const gslice&) const;
3780
  gslice_array<T> operator[](const gslice&);
3781
+ valarray operator[](const valarray<bool>&) const;
3782
  mask_array<T> operator[](const valarray<bool>&);
3783
+ valarray operator[](const valarray<size_t>&) const;
3784
  indirect_array<T> operator[](const valarray<size_t>&);
3785
 
3786
+ // [valarray.unary], unary operators
3787
+ valarray operator+() const;
3788
+ valarray operator-() const;
3789
+ valarray operator~() const;
3790
  valarray<bool> operator!() const;
3791
 
3792
+ // [valarray.cassign], compound assignment
3793
+ valarray& operator*= (const T&);
3794
+ valarray& operator/= (const T&);
3795
+ valarray& operator%= (const T&);
3796
+ valarray& operator+= (const T&);
3797
+ valarray& operator-= (const T&);
3798
+ valarray& operator^= (const T&);
3799
+ valarray& operator&= (const T&);
3800
+ valarray& operator|= (const T&);
3801
+ valarray& operator<<=(const T&);
3802
+ valarray& operator>>=(const T&);
3803
 
3804
+ valarray& operator*= (const valarray&);
3805
+ valarray& operator/= (const valarray&);
3806
+ valarray& operator%= (const valarray&);
3807
+ valarray& operator+= (const valarray&);
3808
+ valarray& operator-= (const valarray&);
3809
+ valarray& operator^= (const valarray&);
3810
+ valarray& operator|= (const valarray&);
3811
+ valarray& operator&= (const valarray&);
3812
+ valarray& operator<<=(const valarray&);
3813
+ valarray& operator>>=(const valarray&);
3814
 
3815
+ // [valarray.members], member functions
3816
  void swap(valarray&) noexcept;
3817
 
3818
  size_t size() const;
3819
 
3820
  T sum() const;
3821
  T min() const;
3822
  T max() const;
3823
 
3824
+ valarray shift (int) const;
3825
+ valarray cshift(int) const;
3826
+ valarray apply(T func(T)) const;
3827
+ valarray apply(T func(const T&)) const;
3828
  void resize(size_t sz, T c = T());
3829
  };
3830
+
3831
+ template<class T, size_t cnt> valarray(const T(&)[cnt], size_t) -> valarray<T>;
3832
  }
3833
  ```
3834
 
3835
  The class template `valarray<T>` is a one-dimensional smart array, with
3836
  elements numbered sequentially from zero. It is a representation of the
3837
+ mathematical concept of an ordered set of values. For convenience, an
3838
+ object of type `valarray<T>` is referred to as an “array” throughout the
3839
+ remainder of  [[numarray]]. The illusion of higher dimensionality may be
3840
+ produced by the familiar idiom of computed indices, together with the
3841
+ powerful subsetting capabilities provided by the generalized subscript
3842
+ operators.[^8]
3843
 
3844
  An implementation is permitted to qualify any of the functions declared
3845
  in `<valarray>` as `inline`.
3846
 
3847
  #### `valarray` constructors <a id="valarray.cons">[[valarray.cons]]</a>
3848
 
3849
  ``` cpp
3850
  valarray();
3851
  ```
3852
 
3853
+ *Effects:* Constructs a `valarray` that has zero length.[^9]
 
3854
 
3855
  ``` cpp
3856
+ explicit valarray(size_t n);
3857
  ```
3858
 
3859
+ *Effects:* Constructs a `valarray` that has length `n`. Each element of
3860
+ the array is value-initialized ([[dcl.init]]).
 
3861
 
3862
  ``` cpp
3863
+ valarray(const T& v, size_t n);
3864
  ```
3865
 
3866
+ *Effects:* Constructs a `valarray` that has length `n`. Each element of
3867
+ the array is initialized with `v`.
 
3868
 
3869
  ``` cpp
3870
+ valarray(const T* p, size_t n);
3871
  ```
3872
 
3873
+ *Requires:* `p` points to an array ([[dcl.array]]) of at least `n`
3874
+ elements.
3875
+
3876
+ *Effects:* Constructs a `valarray` that has length `n`. The values of
3877
+ the elements of the array are initialized with the first `n` values
3878
+ pointed to by the first argument.[^10]
3879
 
3880
  ``` cpp
3881
+ valarray(const valarray& v);
3882
  ```
3883
 
3884
+ *Effects:* Constructs a `valarray` that has the same length as `v`. The
3885
+ elements are initialized with the values of the corresponding elements
3886
+ of `v`.[^11]
3887
 
3888
  ``` cpp
3889
+ valarray(valarray&& v) noexcept;
3890
  ```
3891
 
3892
+ *Effects:* Constructs a `valarray` that has the same length as `v`. The
3893
+ elements are initialized with the values of the corresponding elements
3894
+ of `v`.
3895
 
3896
  *Complexity:* Constant.
3897
 
3898
  ``` cpp
3899
  valarray(initializer_list<T> il);
3900
  ```
3901
 
3902
+ *Effects:* Equivalent to `valarray(il.begin(), il.size())`.
3903
 
3904
  ``` cpp
3905
  valarray(const slice_array<T>&);
3906
  valarray(const gslice_array<T>&);
3907
  valarray(const mask_array<T>&);
 
3913
 
3914
  ``` cpp
3915
  ~valarray();
3916
  ```
3917
 
3918
+ *Effects:* The destructor is applied to every element of `*this`; an
3919
+ implementation may return all allocated memory.
3920
 
3921
  #### `valarray` assignment <a id="valarray.assign">[[valarray.assign]]</a>
3922
 
3923
  ``` cpp
3924
+ valarray& operator=(const valarray& v);
3925
  ```
3926
 
3927
+ *Effects:* Each element of the `*this` array is assigned the value of
3928
+ the corresponding element of `v`. If the length of `v` is not equal to
3929
+ the length of `*this`, resizes `*this` to make the two arrays the same
3930
+ length, as if by calling `resize(v.size())`, before performing the
3931
+ assignment.
3932
 
3933
+ *Postconditions:* `size() == v.size()`.
3934
+
3935
+ *Returns:* `*this`.
3936
 
3937
  ``` cpp
3938
+ valarray& operator=(valarray&& v) noexcept;
3939
  ```
3940
 
3941
  *Effects:* `*this` obtains the value of `v`. The value of `v` after the
3942
  assignment is not specified.
3943
 
3944
+ *Returns:* `*this`.
3945
+
3946
  *Complexity:* Linear.
3947
 
3948
  ``` cpp
3949
  valarray& operator=(initializer_list<T> il);
3950
  ```
3951
 
3952
+ *Effects:* Equivalent to: `return *this = valarray(il);`
 
 
3953
 
3954
  ``` cpp
3955
+ valarray& operator=(const T& v);
3956
  ```
3957
 
3958
+ *Effects:* Assigns `v` to each element of `*this`.
3959
+
3960
+ *Returns:* `*this`.
3961
 
3962
  ``` cpp
3963
+ valarray& operator=(const slice_array<T>&);
3964
+ valarray& operator=(const gslice_array<T>&);
3965
+ valarray& operator=(const mask_array<T>&);
3966
+ valarray& operator=(const indirect_array<T>&);
3967
  ```
3968
 
3969
  *Requires:* The length of the array to which the argument refers equals
3970
+ `size()`. The value of an element in the left-hand side of a `valarray`
3971
+ assignment operator does not depend on the value of another element in
3972
+ that left-hand side.
3973
 
3974
  These operators allow the results of a generalized subscripting
3975
  operation to be assigned directly to a `valarray`.
3976
 
 
 
 
 
3977
  #### `valarray` element access <a id="valarray.access">[[valarray.access]]</a>
3978
 
3979
  ``` cpp
3980
+ const T& operator[](size_t n) const;
3981
+ T& operator[](size_t n);
3982
  ```
3983
 
3984
+ *Requires:* `n < size()`.
 
3985
 
3986
+ *Returns:* A reference to the corresponding element of the array.
 
 
3987
 
3988
+ [*Note 1*: The expression `(a[i] = q, a[i]) == q` evaluates to `true`
3989
+ for any non-constant `valarray<T> a`, any `T q`, and for any `size_t i`
3990
+ such that the value of `i` is less than the length of
3991
+ `a`. — *end note*]
3992
 
3993
+ *Remarks:* The expression `&a[i+j] == &a[i] + j` evaluates to `true` for
3994
+ all `size_t i` and `size_t j` such that `i+j < a.size()`.
3995
+
3996
+ The expression `&a[i] != &b[j]` evaluates to `true` for any two arrays
3997
+ `a` and `b` and for any `size_t i` and `size_t j` such that
3998
+ `i < a.size()` and `j < b.size()`.
3999
+
4000
+ [*Note 2*: This property indicates an absence of aliasing and may be
4001
+ used to advantage by optimizing compilers. Compilers may take advantage
4002
+ of inlining, constant propagation, loop fusion, tracking of pointers
4003
+ obtained from `operator new`, and other techniques to generate efficient
4004
+ `valarray`s. — *end note*]
4005
 
4006
  The reference returned by the subscript operator for an array shall be
4007
  valid until the member function
4008
  `resize(size_t, T)` ([[valarray.members]]) is called for that array or
4009
  until the lifetime of that array ends, whichever happens first.
4010
 
 
 
 
 
4011
  #### `valarray` subset operations <a id="valarray.sub">[[valarray.sub]]</a>
4012
 
4013
  The member `operator[]` is overloaded to provide several ways to select
4014
  sequences of elements from among those controlled by `*this`. Each of
4015
  these operations returns a subset of the array. The const-qualified
 
4019
  `operator=` and other assigning operators to allow selective replacement
4020
  (slicing) of the controlled sequence. In each case the selected
4021
  element(s) must exist.
4022
 
4023
  ``` cpp
4024
+ valarray operator[](slice slicearr) const;
4025
  ```
4026
 
4027
+ *Returns:* A `valarray` containing those elements of the controlled
4028
+ sequence designated by `slicearr`.
4029
+
4030
+ [*Example 1*:
4031
 
4032
  ``` cpp
4033
  const valarray<char> v0("abcdefghijklmnop", 16);
4034
  // v0[slice(2, 5, 3)] returns valarray<char>("cfilo", 5)
4035
  ```
4036
 
4037
+ — *end example*]
4038
+
4039
  ``` cpp
4040
  slice_array<T> operator[](slice slicearr);
4041
  ```
4042
 
4043
  *Returns:* An object that holds references to elements of the controlled
4044
  sequence selected by `slicearr`.
4045
 
4046
+ [*Example 2*:
4047
+
4048
  ``` cpp
4049
  valarray<char> v0("abcdefghijklmnop", 16);
4050
  valarray<char> v1("ABCDE", 5);
4051
  v0[slice(2, 5, 3)] = v1;
4052
  // v0 == valarray<char>("abAdeBghCjkDmnEp", 16);
4053
  ```
4054
 
4055
+ — *end example*]
4056
+
4057
  ``` cpp
4058
+ valarray operator[](const gslice& gslicearr) const;
4059
  ```
4060
 
4061
+ *Returns:* A `valarray` containing those elements of the controlled
4062
+ sequence designated by `gslicearr`.
4063
+
4064
+ [*Example 3*:
4065
 
4066
  ``` cpp
4067
  const valarray<char> v0("abcdefghijklmnop", 16);
4068
  const size_t lv[] = { 2, 3 };
4069
  const size_t dv[] = { 7, 2 };
4070
  const valarray<size_t> len(lv, 2), str(dv, 2);
4071
  // v0[gslice(3, len, str)] returns
4072
  // valarray<char>("dfhkmo", 6)
4073
  ```
4074
 
4075
+ — *end example*]
4076
+
4077
  ``` cpp
4078
  gslice_array<T> operator[](const gslice& gslicearr);
4079
  ```
4080
 
4081
  *Returns:* An object that holds references to elements of the controlled
4082
  sequence selected by `gslicearr`.
4083
 
4084
+ [*Example 4*:
4085
+
4086
  ``` cpp
4087
  valarray<char> v0("abcdefghijklmnop", 16);
4088
+ valarray<char> v1("ABCDEF", 6);
4089
  const size_t lv[] = { 2, 3 };
4090
  const size_t dv[] = { 7, 2 };
4091
  const valarray<size_t> len(lv, 2), str(dv, 2);
4092
  v0[gslice(3, len, str)] = v1;
4093
  // v0 == valarray<char>("abcAeBgCijDlEnFp", 16)
4094
  ```
4095
 
4096
+ — *end example*]
4097
+
4098
  ``` cpp
4099
+ valarray operator[](const valarray<bool>& boolarr) const;
4100
  ```
4101
 
4102
+ *Returns:* A `valarray` containing those elements of the controlled
4103
+ sequence designated by `boolarr`.
4104
+
4105
+ [*Example 5*:
4106
 
4107
  ``` cpp
4108
  const valarray<char> v0("abcdefghijklmnop", 16);
4109
  const bool vb[] = { false, false, true, true, false, true };
4110
  // v0[valarray<bool>(vb, 6)] returns
4111
  // valarray<char>("cdf", 3)
4112
  ```
4113
 
4114
+ — *end example*]
4115
+
4116
  ``` cpp
4117
  mask_array<T> operator[](const valarray<bool>& boolarr);
4118
  ```
4119
 
4120
  *Returns:* An object that holds references to elements of the controlled
4121
  sequence selected by `boolarr`.
4122
 
4123
+ [*Example 6*:
4124
+
4125
  ``` cpp
4126
  valarray<char> v0("abcdefghijklmnop", 16);
4127
  valarray<char> v1("ABC", 3);
4128
  const bool vb[] = { false, false, true, true, false, true };
4129
  v0[valarray<bool>(vb, 6)] = v1;
4130
  // v0 == valarray<char>("abABeCghijklmnop", 16)
4131
  ```
4132
 
4133
+ — *end example*]
4134
+
4135
  ``` cpp
4136
+ valarray operator[](const valarray<size_t>& indarr) const;
4137
  ```
4138
 
4139
+ *Returns:* A `valarray` containing those elements of the controlled
4140
+ sequence designated by `indarr`.
4141
+
4142
+ [*Example 7*:
4143
 
4144
  ``` cpp
4145
  const valarray<char> v0("abcdefghijklmnop", 16);
4146
  const size_t vi[] = { 7, 5, 2, 3, 8 };
4147
  // v0[valarray<size_t>(vi, 5)] returns
4148
  // valarray<char>("hfcdi", 5)
4149
  ```
4150
 
4151
+ — *end example*]
4152
+
4153
  ``` cpp
4154
  indirect_array<T> operator[](const valarray<size_t>& indarr);
4155
  ```
4156
 
4157
  *Returns:* An object that holds references to elements of the controlled
4158
  sequence selected by `indarr`.
4159
 
4160
+ [*Example 8*:
4161
+
4162
  ``` cpp
4163
  valarray<char> v0("abcdefghijklmnop", 16);
4164
  valarray<char> v1("ABCDE", 5);
4165
  const size_t vi[] = { 7, 5, 2, 3, 8 };
4166
  v0[valarray<size_t>(vi, 5)] = v1;
4167
  // v0 == valarray<char>("abCDeBgAEjklmnop", 16)
4168
  ```
4169
 
4170
+ — *end example*]
4171
+
4172
  #### `valarray` unary operators <a id="valarray.unary">[[valarray.unary]]</a>
4173
 
4174
  ``` cpp
4175
+ valarray operator+() const;
4176
+ valarray operator-() const;
4177
+ valarray operator~() const;
4178
  valarray<bool> operator!() const;
4179
  ```
4180
 
4181
+ *Requires:* Each of these operators may only be instantiated for a type
4182
+ `T` to which the indicated operator can be applied and for which the
4183
+ indicated operator returns a value which is of type `T` (`bool` for
4184
+ `operator!`) or which may be unambiguously implicitly converted to type
4185
+ `T` (`bool` for `operator!`).
4186
 
4187
+ *Returns:* A `valarray` whose length is `size()`. Each element of the
4188
+ returned array is initialized with the result of applying the indicated
4189
+ operator to the corresponding element of the array.
 
4190
 
4191
+ #### `valarray` compound assignment <a id="valarray.cassign">[[valarray.cassign]]</a>
4192
 
4193
  ``` cpp
4194
+ valarray& operator*= (const valarray& v);
4195
+ valarray& operator/= (const valarray& v);
4196
+ valarray& operator%= (const valarray& v);
4197
+ valarray& operator+= (const valarray& v);
4198
+ valarray& operator-= (const valarray& v);
4199
+ valarray& operator^= (const valarray& v);
4200
+ valarray& operator&= (const valarray& v);
4201
+ valarray& operator|= (const valarray& v);
4202
+ valarray& operator<<=(const valarray& v);
4203
+ valarray& operator>>=(const valarray& v);
4204
  ```
4205
 
4206
+ *Requires:* `size() == v.size()`. Each of these operators may only be
4207
+ instantiated for a type `T` if the indicated operator can be applied to
4208
+ two operands of type `T`. The value of an element in the left-hand side
4209
+ of a valarray compound assignment operator does not depend on the value
4210
+ of another element in that left hand side.
4211
 
4212
+ *Effects:* Each of these operators performs the indicated operation on
4213
+ each of the elements of `*this` and the corresponding element of `v`.
4214
 
4215
+ *Returns:* `*this`.
 
 
4216
 
4217
+ *Remarks:* The appearance of an array on the left-hand side of a
4218
+ compound assignment does not invalidate references or pointers.
 
4219
 
4220
  ``` cpp
4221
+ valarray& operator*= (const T& v);
4222
+ valarray& operator/= (const T& v);
4223
+ valarray& operator%= (const T& v);
4224
+ valarray& operator+= (const T& v);
4225
+ valarray& operator-= (const T& v);
4226
+ valarray& operator^= (const T& v);
4227
+ valarray& operator&= (const T& v);
4228
+ valarray& operator|= (const T& v);
4229
+ valarray& operator<<=(const T& v);
4230
+ valarray& operator>>=(const T& v);
4231
  ```
4232
 
4233
+ *Requires:* Each of these operators may only be instantiated for a type
4234
+ `T` if the indicated operator can be applied to two operands of type
4235
+ `T`.
4236
 
4237
+ *Effects:* Each of these operators applies the indicated operation to
4238
+ each element of `*this` and `v`.
4239
 
4240
+ *Returns:* `*this`
4241
 
4242
+ *Remarks:* The appearance of an array on the left-hand side of a
4243
+ compound assignment does not invalidate references or pointers to the
4244
+ elements of the array.
4245
 
4246
  #### `valarray` member functions <a id="valarray.members">[[valarray.members]]</a>
4247
 
4248
  ``` cpp
4249
  void swap(valarray& v) noexcept;
 
4264
 
4265
  ``` cpp
4266
  T sum() const;
4267
  ```
4268
 
4269
+ *Requires:* `size() > 0`. This function may only be instantiated for a
4270
+ type `T` to which `operator+=` can be applied.
 
4271
 
4272
+ *Returns:* The sum of all the elements of the array. If the array has
4273
+ length 1, returns the value of element 0. Otherwise, the returned value
4274
+ is calculated by applying `operator+=` to a copy of an element of the
4275
+ array and all other elements of the array in an unspecified order.
 
4276
 
4277
  ``` cpp
4278
  T min() const;
4279
  ```
4280
 
4281
+ *Requires:* `size() > 0`
4282
+
4283
+ *Returns:* The minimum value contained in `*this`. For an array of
4284
+ length 1, the value of element 0 is returned. For all other array
4285
+ lengths, the determination is made using `operator<`.
4286
 
4287
  ``` cpp
4288
  T max() const;
4289
  ```
4290
 
4291
+ *Requires:* `size() > 0`.
4292
+
4293
+ *Returns:* The maximum value contained in `*this`. For an array of
4294
+ length 1, the value of element 0 is returned. For all other array
4295
+ lengths, the determination is made using `operator<`.
4296
 
4297
  ``` cpp
4298
+ valarray shift(int n) const;
4299
  ```
4300
 
4301
+ *Returns:* A `valarray` of length `size()`, each of whose elements *I*
4302
+ is `(*this)[`*`I`*` + n]` if *`I`*` + n` is non-negative and less than
4303
+ `size()`, otherwise `T()`.
4304
+
4305
+ [*Note 1*: If element zero is taken as the leftmost element, a positive
4306
+ value of `n` shifts the elements left `n` places, with zero
4307
+ fill. — *end note*]
4308
+
4309
+ [*Example 1*: If the argument has the value -2, the first two elements
4310
+ of the result will be value-initialized ([[dcl.init]]); the third
4311
+ element of the result will be assigned the value of the first element of
4312
+ the argument; etc. — *end example*]
4313
+
4314
  ``` cpp
4315
+ valarray cshift(int n) const;
4316
  ```
4317
 
4318
+ *Returns:* A `valarray` of length `size()` that is a circular shift of
4319
+ `*this`. If element zero is taken as the leftmost element, a
4320
+ non-negative value of n shifts the elements circularly left n places and
4321
+ a negative value of n shifts the elements circularly right -n places.
4322
+
4323
  ``` cpp
4324
+ valarray apply(T func(T)) const;
4325
+ valarray apply(T func(const T&)) const;
4326
  ```
4327
 
4328
+ *Returns:* A `valarray` whose length is `size()`. Each element of the
4329
+ returned array is assigned the value returned by applying the argument
4330
+ function to the corresponding element of `*this`.
4331
+
4332
  ``` cpp
4333
  void resize(size_t sz, T c = T());
4334
  ```
4335
 
4336
+ *Effects:* Changes the length of the `*this` array to `sz` and then
4337
+ assigns to each element the value of the second argument. Resizing
4338
+ invalidates all pointers and references to elements in the array.
4339
+
4340
  ### `valarray` non-member operations <a id="valarray.nonmembers">[[valarray.nonmembers]]</a>
4341
 
4342
  #### `valarray` binary operators <a id="valarray.binary">[[valarray.binary]]</a>
4343
 
4344
  ``` cpp
 
4362
  (const valarray<T>&, const valarray<T>&);
4363
  template<class T> valarray<T> operator>>
4364
  (const valarray<T>&, const valarray<T>&);
4365
  ```
4366
 
4367
+ *Requires:* Each of these operators may only be instantiated for a type
4368
+ `T` to which the indicated operator can be applied and for which the
4369
+ indicated operator returns a value which is of type `T` or which can be
4370
+ unambiguously implicitly converted to type `T`. The argument arrays have
4371
+ the same length.
4372
 
4373
+ *Returns:* A `valarray` whose length is equal to the lengths of the
4374
+ argument arrays. Each element of the returned array is initialized with
4375
+ the result of applying the indicated operator to the corresponding
4376
+ elements of the argument arrays.
 
 
 
4377
 
4378
  ``` cpp
4379
  template<class T> valarray<T> operator* (const valarray<T>&, const T&);
4380
  template<class T> valarray<T> operator* (const T&, const valarray<T>&);
4381
  template<class T> valarray<T> operator/ (const valarray<T>&, const T&);
 
4396
  template<class T> valarray<T> operator<<(const T&, const valarray<T>&);
4397
  template<class T> valarray<T> operator>>(const valarray<T>&, const T&);
4398
  template<class T> valarray<T> operator>>(const T&, const valarray<T>&);
4399
  ```
4400
 
4401
+ *Requires:* Each of these operators may only be instantiated for a type
4402
+ `T` to which the indicated operator can be applied and for which the
4403
+ indicated operator returns a value which is of type `T` or which can be
4404
  unambiguously implicitly converted to type `T`.
4405
 
4406
+ *Returns:* A `valarray` whose length is equal to the length of the array
4407
+ argument. Each element of the returned array is initialized with the
4408
+ result of applying the indicated operator to the corresponding element
4409
+ of the array argument and the non-array argument.
4410
 
4411
  #### `valarray` logical operators <a id="valarray.comparison">[[valarray.comparison]]</a>
4412
 
4413
  ``` cpp
4414
  template<class T> valarray<bool> operator==
 
4427
  (const valarray<T>&, const valarray<T>&);
4428
  template<class T> valarray<bool> operator||
4429
  (const valarray<T>&, const valarray<T>&);
4430
  ```
4431
 
4432
+ *Requires:* Each of these operators may only be instantiated for a type
4433
+ `T` to which the indicated operator can be applied and for which the
4434
+ indicated operator returns a value which is of type `bool` or which can
4435
+ be unambiguously implicitly converted to type `bool`. The two array
4436
+ arguments have the same length.
4437
 
4438
+ *Returns:* A `valarray<bool>` whose length is equal to the length of the
4439
+ array arguments. Each element of the returned array is initialized with
4440
+ the result of applying the indicated operator to the corresponding
4441
+ elements of the argument arrays.
 
 
 
4442
 
4443
  ``` cpp
4444
  template<class T> valarray<bool> operator==(const valarray<T>&, const T&);
4445
  template<class T> valarray<bool> operator==(const T&, const valarray<T>&);
4446
  template<class T> valarray<bool> operator!=(const valarray<T>&, const T&);
 
4457
  template<class T> valarray<bool> operator&&(const T&, const valarray<T>&);
4458
  template<class T> valarray<bool> operator||(const valarray<T>&, const T&);
4459
  template<class T> valarray<bool> operator||(const T&, const valarray<T>&);
4460
  ```
4461
 
4462
+ *Requires:* Each of these operators may only be instantiated for a type
4463
+ `T` to which the indicated operator can be applied and for which the
4464
+ indicated operator returns a value which is of type `bool` or which can
4465
+ be unambiguously implicitly converted to type `bool`.
4466
 
4467
+ *Returns:* A `valarray<bool>` whose length is equal to the length of the
4468
+ array argument. Each element of the returned array is initialized with
4469
+ the result of applying the indicated operator to the corresponding
4470
+ element of the array and the non-array argument.
4471
 
4472
  #### `valarray` transcendentals <a id="valarray.transcend">[[valarray.transcend]]</a>
4473
 
4474
  ``` cpp
4475
  template<class T> valarray<T> abs (const valarray<T>&);
 
4494
  template<class T> valarray<T> sqrt (const valarray<T>&);
4495
  template<class T> valarray<T> tan (const valarray<T>&);
4496
  template<class T> valarray<T> tanh (const valarray<T>&);
4497
  ```
4498
 
4499
+ *Requires:* Each of these functions may only be instantiated for a type
4500
+ `T` to which a unique function with the indicated name can be applied
4501
+ (unqualified). This function shall return a value which is of type `T`
4502
+ or which can be unambiguously implicitly converted to type `T`.
4503
 
4504
  #### `valarray` specialized algorithms <a id="valarray.special">[[valarray.special]]</a>
4505
 
4506
  ``` cpp
4507
  template <class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
4508
  ```
4509
 
4510
+ *Effects:* Equivalent to `x.swap(y)`.
4511
 
4512
  ### Class `slice` <a id="class.slice">[[class.slice]]</a>
4513
 
4514
  #### Class `slice` overview <a id="class.slice.overview">[[class.slice.overview]]</a>
4515
 
 
4526
  };
4527
  }
4528
  ```
4529
 
4530
  The `slice` class represents a BLAS-like slice from an array. Such a
4531
+ slice is specified by a starting index, a length, and a stride.[^12]
4532
 
4533
  #### `slice` constructors <a id="cons.slice">[[cons.slice]]</a>
4534
 
4535
  ``` cpp
4536
  slice();
 
4541
  The default constructor is equivalent to `slice(0, 0, 0)`. A default
4542
  constructor is provided only to permit the declaration of arrays of
4543
  slices. The constructor with arguments for a slice takes a start,
4544
  length, and stride parameter.
4545
 
4546
+ [*Example 1*: `slice(3, 8, 2)` constructs a slice which selects
4547
+ elements 3, 5, 7, ... 17 from an array. — *end example*]
4548
 
4549
  #### `slice` access functions <a id="slice.access">[[slice.access]]</a>
4550
 
4551
  ``` cpp
4552
  size_t start() const;
 
4564
 
4565
  ``` cpp
4566
  namespace std {
4567
  template <class T> class slice_array {
4568
  public:
4569
+ using value_type = T;
4570
 
4571
  void operator= (const valarray<T>&) const;
4572
  void operator*= (const valarray<T>&) const;
4573
  void operator/= (const valarray<T>&) const;
4574
  void operator%= (const valarray<T>&) const;
 
4598
  ```
4599
 
4600
  It has reference semantics to a subset of an array specified by a
4601
  `slice` object.
4602
 
4603
+ [*Example 1*: The expression `a[slice(1, 5, 3)] = b;` has the effect of
4604
+ assigning the elements of `b` to a slice of the elements in `a`. For the
4605
+ slice shown, the elements selected from `a` are 1, 4, ...,
4606
+ 13. — *end example*]
4607
 
4608
  #### `slice_array` assignment <a id="slice.arr.assign">[[slice.arr.assign]]</a>
4609
 
4610
  ``` cpp
4611
  void operator=(const valarray<T>&) const;
 
4614
 
4615
  These assignment operators have reference semantics, assigning the
4616
  values of the argument array elements to selected elements of the
4617
  `valarray<T>` object to which the `slice_array` object refers.
4618
 
4619
+ #### `slice_array` compound assignment <a id="slice.arr.comp.assign">[[slice.arr.comp.assign]]</a>
4620
 
4621
  ``` cpp
4622
  void operator*= (const valarray<T>&) const;
4623
  void operator/= (const valarray<T>&) const;
4624
  void operator%= (const valarray<T>&) const;
 
4629
  void operator|= (const valarray<T>&) const;
4630
  void operator<<=(const valarray<T>&) const;
4631
  void operator>>=(const valarray<T>&) const;
4632
  ```
4633
 
4634
+ These compound assignments have reference semantics, applying the
4635
  indicated operation to the elements of the argument array and selected
4636
  elements of the `valarray<T>` object to which the `slice_array` object
4637
  refers.
4638
 
4639
  #### `slice_array` fill function <a id="slice.arr.fill">[[slice.arr.fill]]</a>
 
4673
  building multidimensional array classes using the `valarray` template,
4674
  which is one-dimensional. The set of one-dimensional index values
4675
  specified by a `gslice` are $$k = s + \sum_j i_j d_j$$ where the
4676
  multidimensional indices iⱼ range in value from 0 to lᵢⱼ - 1.
4677
 
4678
+ [*Example 1*:
4679
+
4680
  The `gslice` specification
4681
 
4682
  ``` cpp
4683
  start = 3
4684
  length = {2, 4, 3}
4685
  stride = {19, 4, 1}
4686
  ```
4687
 
4688
  yields the sequence of one-dimensional indices
 
4689
  $$k = 3 + (0, 1) \times 19 + (0, 1, 2, 3) \times 4 + (0, 1, 2) \times 1$$
 
4690
  which are ordered as shown in the following table:
4691
 
4692
  That is, the highest-ordered index turns fastest.
4693
 
4694
+ — *end example*]
4695
+
4696
  It is possible to have degenerate generalized slices in which an address
4697
  is repeated.
4698
 
4699
+ [*Example 2*:
4700
+
4701
  If the stride parameters in the previous example are changed to {1, 1,
4702
  1}, the first few elements of the resulting sequence of indices will be
4703
 
4704
+ — *end example*]
4705
+
4706
  If a degenerate slice is used as the argument to the non-`const` version
4707
+ of `operator[](const gslice&)`, the behavior is undefined.
4708
 
4709
  #### `gslice` constructors <a id="gslice.cons">[[gslice.cons]]</a>
4710
 
4711
  ``` cpp
4712
  gslice();
 
4740
 
4741
  ``` cpp
4742
  namespace std {
4743
  template <class T> class gslice_array {
4744
  public:
4745
+ using value_type = T;
4746
 
4747
  void operator= (const valarray<T>&) const;
4748
  void operator*= (const valarray<T>&) const;
4749
  void operator/= (const valarray<T>&) const;
4750
  void operator%= (const valarray<T>&) const;
 
4789
 
4790
  These assignment operators have reference semantics, assigning the
4791
  values of the argument array elements to selected elements of the
4792
  `valarray<T>` object to which the `gslice_array` refers.
4793
 
4794
+ #### `gslice_array` compound assignment <a id="gslice.array.comp.assign">[[gslice.array.comp.assign]]</a>
4795
 
4796
  ``` cpp
4797
  void operator*= (const valarray<T>&) const;
4798
  void operator/= (const valarray<T>&) const;
4799
  void operator%= (const valarray<T>&) const;
 
4804
  void operator|= (const valarray<T>&) const;
4805
  void operator<<=(const valarray<T>&) const;
4806
  void operator>>=(const valarray<T>&) const;
4807
  ```
4808
 
4809
+ These compound assignments have reference semantics, applying the
4810
  indicated operation to the elements of the argument array and selected
4811
  elements of the `valarray<T>` object to which the `gslice_array` object
4812
  refers.
4813
 
4814
  #### `gslice_array` fill function <a id="gslice.array.fill">[[gslice.array.fill]]</a>
 
4827
 
4828
  ``` cpp
4829
  namespace std {
4830
  template <class T> class mask_array {
4831
  public:
4832
+ using value_type = T;
4833
 
4834
  void operator= (const valarray<T>&) const;
4835
  void operator*= (const valarray<T>&) const;
4836
  void operator/= (const valarray<T>&) const;
4837
  void operator%= (const valarray<T>&) const;
 
4873
 
4874
  These assignment operators have reference semantics, assigning the
4875
  values of the argument array elements to selected elements of the
4876
  `valarray<T>` object to which it refers.
4877
 
4878
+ #### `mask_array` compound assignment <a id="mask.array.comp.assign">[[mask.array.comp.assign]]</a>
4879
 
4880
  ``` cpp
4881
  void operator*= (const valarray<T>&) const;
4882
  void operator/= (const valarray<T>&) const;
4883
  void operator%= (const valarray<T>&) const;
 
4888
  void operator|= (const valarray<T>&) const;
4889
  void operator<<=(const valarray<T>&) const;
4890
  void operator>>=(const valarray<T>&) const;
4891
  ```
4892
 
4893
+ These compound assignments have reference semantics, applying the
4894
  indicated operation to the elements of the argument array and selected
4895
  elements of the `valarray<T>` object to which the mask object refers.
4896
 
4897
  #### `mask_array` fill function <a id="mask.array.fill">[[mask.array.fill]]</a>
4898
 
 
4910
 
4911
  ``` cpp
4912
  namespace std {
4913
  template <class T> class indirect_array {
4914
  public:
4915
+ using value_type = T;
4916
 
4917
  void operator= (const valarray<T>&) const;
4918
  void operator*= (const valarray<T>&) const;
4919
  void operator/= (const valarray<T>&) const;
4920
  void operator%= (const valarray<T>&) const;
 
4960
  `valarray<T>` object to which it refers.
4961
 
4962
  If the `indirect_array` specifies an element in the `valarray<T>` object
4963
  to which it refers more than once, the behavior is undefined.
4964
 
4965
+ [*Example 1*:
4966
+
4967
  ``` cpp
4968
  int addr[] = {2, 3, 1, 4, 4};
4969
  valarray<size_t> indirect(addr, 5);
4970
  valarray<double> a(0., 10), b(1., 5);
4971
  a[indirect] = b;
4972
  ```
4973
 
4974
  results in undefined behavior since element 4 is specified twice in the
4975
  indirection.
4976
 
4977
+ *end example*]
4978
+
4979
+ #### `indirect_array` compound assignment <a id="indirect.array.comp.assign">[[indirect.array.comp.assign]]</a>
4980
 
4981
  ``` cpp
4982
  void operator*= (const valarray<T>&) const;
4983
  void operator/= (const valarray<T>&) const;
4984
  void operator%= (const valarray<T>&) const;
 
4989
  void operator|= (const valarray<T>&) const;
4990
  void operator<<=(const valarray<T>&) const;
4991
  void operator>>=(const valarray<T>&) const;
4992
  ```
4993
 
4994
+ These compound assignments have reference semantics, applying the
4995
  indicated operation to the elements of the argument array and selected
4996
  elements of the `valarray<T>` object to which the `indirect_array`
4997
  object refers.
4998
 
4999
  If the `indirect_array` specifies an element in the `valarray<T>` object
 
5007
 
5008
  This function has reference semantics, assigning the value of its
5009
  argument to the elements of the `valarray<T>` object to which the
5010
  `indirect_array` object refers.
5011
 
5012
+ ### `valarray` range access <a id="valarray.range">[[valarray.range]]</a>
5013
 
5014
  In the `begin` and `end` function templates that follow, *unspecified*1
5015
  is a type that meets the requirements of a mutable random access
5016
+ iterator ([[random.access.iterators]]) and of a contiguous iterator (
5017
+ [[iterator.requirements.general]]) whose `value_type` is the template
5018
+ parameter `T` and whose `reference` type is `T&`. *unspecified*2 is a
5019
+ type that meets the requirements of a constant random access iterator (
5020
+ [[random.access.iterators]]) and of a contiguous iterator (
5021
+ [[iterator.requirements.general]]) whose `value_type` is the template
5022
+ parameter `T` and whose `reference` type is `const T&`.
5023
 
5024
  The iterators returned by `begin` and `end` for an array are guaranteed
5025
  to be valid until the member function `resize(size_t, T)` (
5026
  [[valarray.members]]) is called for that array or until the lifetime of
5027
  that array ends, whichever happens first.
 
5029
  ``` cpp
5030
  template <class T> unspecified{1} begin(valarray<T>& v);
5031
  template <class T> unspecified{2} begin(const valarray<T>& v);
5032
  ```
5033
 
5034
+ *Returns:* An iterator referencing the first value in the array.
5035
 
5036
  ``` cpp
5037
  template <class T> unspecified{1} end(valarray<T>& v);
5038
  template <class T> unspecified{2} end(const valarray<T>& v);
5039
  ```
5040
 
5041
+ *Returns:* An iterator referencing one past the last value in the array.
 
5042
 
5043
  ## Generalized numeric operations <a id="numeric.ops">[[numeric.ops]]</a>
5044
 
5045
  ### Header `<numeric>` synopsis <a id="numeric.ops.overview">[[numeric.ops.overview]]</a>
5046
 
5047
  ``` cpp
5048
  namespace std {
5049
+ // [accumulate], accumulate
5050
  template <class InputIterator, class T>
5051
  T accumulate(InputIterator first, InputIterator last, T init);
5052
  template <class InputIterator, class T, class BinaryOperation>
5053
  T accumulate(InputIterator first, InputIterator last, T init,
5054
  BinaryOperation binary_op);
5055
 
5056
+ // [reduce], reduce
5057
+ template<class InputIterator>
5058
+ typename iterator_traits<InputIterator>::value_type
5059
+ reduce(InputIterator first, InputIterator last);
5060
+ template<class InputIterator, class T>
5061
+ T reduce(InputIterator first, InputIterator last, T init);
5062
+ template<class InputIterator, class T, class BinaryOperation>
5063
+ T reduce(InputIterator first, InputIterator last, T init,
5064
+ BinaryOperation binary_op);
5065
+ template<class ExecutionPolicy, class ForwardIterator>
5066
+ typename iterator_traits<ForwardIterator>::value_type
5067
+ reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5068
+ ForwardIterator first, ForwardIterator last);
5069
+ template<class ExecutionPolicy, class ForwardIterator, class T>
5070
+ T reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5071
+ ForwardIterator first, ForwardIterator last, T init);
5072
+ template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
5073
+ T reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5074
+ ForwardIterator first, ForwardIterator last, T init,
5075
+ BinaryOperation binary_op);
5076
+
5077
+ // [inner.product], inner product
5078
  template <class InputIterator1, class InputIterator2, class T>
5079
  T inner_product(InputIterator1 first1, InputIterator1 last1,
5080
  InputIterator2 first2, T init);
5081
  template <class InputIterator1, class InputIterator2, class T,
5082
  class BinaryOperation1, class BinaryOperation2>
5083
  T inner_product(InputIterator1 first1, InputIterator1 last1,
5084
  InputIterator2 first2, T init,
5085
  BinaryOperation1 binary_op1,
5086
  BinaryOperation2 binary_op2);
5087
 
5088
+ // [transform.reduce], transform reduce
5089
+ template<class InputIterator1, class InputIterator2, class T>
5090
+ T transform_reduce(InputIterator1 first1, InputIterator1 last1,
5091
+ InputIterator2 first2,
5092
+ T init);
5093
+ template<class InputIterator1, class InputIterator2, class T,
5094
+ class BinaryOperation1, class BinaryOperation2>
5095
+ T transform_reduce(InputIterator1 first1, InputIterator1 last1,
5096
+ InputIterator2 first2,
5097
+ T init,
5098
+ BinaryOperation1 binary_op1,
5099
+ BinaryOperation2 binary_op2);
5100
+ template<class InputIterator, class T,
5101
+ class BinaryOperation, class UnaryOperation>
5102
+ T transform_reduce(InputIterator first, InputIterator last,
5103
+ T init,
5104
+ BinaryOperation binary_op, UnaryOperation unary_op);
5105
+ template<class ExecutionPolicy,
5106
+ class ForwardIterator1, class ForwardIterator2, class T>
5107
+ T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5108
+ ForwardIterator1 first1, ForwardIterator1 last1,
5109
+ ForwardIterator2 first2,
5110
+ T init);
5111
+ template<class ExecutionPolicy,
5112
+ class ForwardIterator1, class ForwardIterator2, class T,
5113
+ class BinaryOperation1, class BinaryOperation2>
5114
+ T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5115
+ ForwardIterator1 first1, ForwardIterator1 last1,
5116
+ ForwardIterator2 first2,
5117
+ T init,
5118
+ BinaryOperation1 binary_op1,
5119
+ BinaryOperation2 binary_op2);
5120
+ template<class ExecutionPolicy,
5121
+ class ForwardIterator, class T,
5122
+ class BinaryOperation, class UnaryOperation>
5123
+ T transform_reduce(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5124
+ ForwardIterator first, ForwardIterator last,
5125
+ T init,
5126
+ BinaryOperation binary_op, UnaryOperation unary_op);
5127
+
5128
+ // [partial.sum], partial sum
5129
  template <class InputIterator, class OutputIterator>
5130
  OutputIterator partial_sum(InputIterator first,
5131
  InputIterator last,
5132
  OutputIterator result);
5133
+ template <class InputIterator, class OutputIterator, class BinaryOperation>
 
5134
  OutputIterator partial_sum(InputIterator first,
5135
  InputIterator last,
5136
  OutputIterator result,
5137
  BinaryOperation binary_op);
5138
 
5139
+ // [exclusive.scan], exclusive scan
5140
+ template<class InputIterator, class OutputIterator, class T>
5141
+ OutputIterator exclusive_scan(InputIterator first, InputIterator last,
5142
+ OutputIterator result,
5143
+ T init);
5144
+ template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
5145
+ OutputIterator exclusive_scan(InputIterator first, InputIterator last,
5146
+ OutputIterator result,
5147
+ T init, BinaryOperation binary_op);
5148
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
5149
+ ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5150
+ ForwardIterator1 first, ForwardIterator1 last,
5151
+ ForwardIterator2 result,
5152
+ T init);
5153
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T,
5154
+ class BinaryOperation>
5155
+ ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5156
+ ForwardIterator1 first, ForwardIterator1 last,
5157
+ ForwardIterator2 result,
5158
+ T init, BinaryOperation binary_op);
5159
+
5160
+ // [inclusive.scan], inclusive scan
5161
+ template<class InputIterator, class OutputIterator>
5162
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5163
+ OutputIterator result);
5164
+ template<class InputIterator, class OutputIterator, class BinaryOperation>
5165
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5166
+ OutputIterator result,
5167
+ BinaryOperation binary_op);
5168
+ template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
5169
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5170
+ OutputIterator result,
5171
+ BinaryOperation binary_op, T init);
5172
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
5173
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5174
+ ForwardIterator1 first, ForwardIterator1 last,
5175
+ ForwardIterator2 result);
5176
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
5177
+ class BinaryOperation>
5178
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5179
+ ForwardIterator1 first, ForwardIterator1 last,
5180
+ ForwardIterator2 result,
5181
+ BinaryOperation binary_op);
5182
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
5183
+ class BinaryOperation, class T>
5184
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5185
+ ForwardIterator1 first, ForwardIterator1 last,
5186
+ ForwardIterator2 result,
5187
+ BinaryOperation binary_op, T init);
5188
+
5189
+ // [transform.exclusive.scan], transform exclusive scan
5190
+ template<class InputIterator, class OutputIterator, class T,
5191
+ class BinaryOperation, class UnaryOperation>
5192
+ OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last,
5193
+ OutputIterator result,
5194
+ T init,
5195
+ BinaryOperation binary_op,
5196
+ UnaryOperation unary_op);
5197
+ template<class ExecutionPolicy,
5198
+ class ForwardIterator1, class ForwardIterator2, class T,
5199
+ class BinaryOperation, class UnaryOperation>
5200
+ ForwardIterator2 transform_exclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5201
+ ForwardIterator1 first, ForwardIterator1 last,
5202
+ ForwardIterator2 result,
5203
+ T init,
5204
+ BinaryOperation binary_op,
5205
+ UnaryOperation unary_op);
5206
+
5207
+ // [transform.inclusive.scan], transform inclusive scan
5208
+ template<class InputIterator, class OutputIterator,
5209
+ class BinaryOperation, class UnaryOperation>
5210
+ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
5211
+ OutputIterator result,
5212
+ BinaryOperation binary_op,
5213
+ UnaryOperation unary_op);
5214
+ template<class InputIterator, class OutputIterator,
5215
+ class BinaryOperation, class UnaryOperation, class T>
5216
+ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
5217
+ OutputIterator result,
5218
+ BinaryOperation binary_op,
5219
+ UnaryOperation unary_op,
5220
+ T init);
5221
+ template<class ExecutionPolicy,
5222
+ class ForwardIterator1, class ForwardIterator2,
5223
+ class BinaryOperation, class UnaryOperation>
5224
+ ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5225
+ ForwardIterator1 first, ForwardIterator1 last,
5226
+ ForwardIterator2 result,
5227
+ BinaryOperation binary_op,
5228
+ UnaryOperation unary_op);
5229
+ template<class ExecutionPolicy,
5230
+ class ForwardIterator1, class ForwardIterator2,
5231
+ class BinaryOperation, class UnaryOperation, class T>
5232
+ ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5233
+ ForwardIterator1 first, ForwardIterator1 last,
5234
+ ForwardIterator2 result,
5235
+ BinaryOperation binary_op,
5236
+ UnaryOperation unary_op,
5237
+ T init);
5238
+
5239
+ // [adjacent.difference], adjacent difference
5240
  template <class InputIterator, class OutputIterator>
5241
  OutputIterator adjacent_difference(InputIterator first,
5242
  InputIterator last,
5243
  OutputIterator result);
5244
+ template <class InputIterator, class OutputIterator, class BinaryOperation>
 
5245
  OutputIterator adjacent_difference(InputIterator first,
5246
  InputIterator last,
5247
  OutputIterator result,
5248
  BinaryOperation binary_op);
5249
+ template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
5250
+ ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5251
+ ForwardIterator1 first,
5252
+ ForwardIterator1 last,
5253
+ ForwardIterator2 result);
5254
+ template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
5255
+ class BinaryOperation>
5256
+ ForwardIterator2 adjacent_difference(ExecutionPolicy&& exec, // see [algorithms.parallel.overloads]
5257
+ ForwardIterator1 first,
5258
+ ForwardIterator1 last,
5259
+ ForwardIterator2 result,
5260
+ BinaryOperation binary_op);
5261
 
5262
+ // [numeric.iota], iota
5263
  template <class ForwardIterator, class T>
5264
  void iota(ForwardIterator first, ForwardIterator last, T value);
5265
+
5266
+ // [numeric.ops.gcd], greatest common divisor
5267
+ template <class M, class N>
5268
+ constexpr common_type_t<M,N> gcd(M m, N n);
5269
+
5270
+ // [numeric.ops.lcm], least common multiple
5271
+ template <class M, class N>
5272
+ constexpr common_type_t<M,N> lcm(M m, N n);
5273
  }
5274
  ```
5275
 
5276
  The requirements on the types of algorithms’ arguments that are
5277
  described in the introduction to Clause  [[algorithms]] also apply to
5278
  the following algorithms.
5279
 
5280
+ Throughout this subclause, the parameters `UnaryOperation`,
5281
+ `BinaryOperation`, `BinaryOperation1`, and `BinaryOperation2` are used
5282
+ whenever an algorithm expects a function object ([[function.objects]]).
5283
+
5284
+ [*Note 1*: The use of closed ranges as well as semi-open ranges to
5285
+ specify requirements throughout this subclause is
5286
+ intentional. — *end note*]
5287
+
5288
  ### Accumulate <a id="accumulate">[[accumulate]]</a>
5289
 
5290
  ``` cpp
5291
  template <class InputIterator, class T>
5292
  T accumulate(InputIterator first, InputIterator last, T init);
5293
  template <class InputIterator, class T, class BinaryOperation>
5294
  T accumulate(InputIterator first, InputIterator last, T init,
5295
  BinaryOperation binary_op);
5296
  ```
5297
 
5298
+ *Requires:* `T` shall meet the requirements of `CopyConstructible`
5299
+ (Table  [[tab:copyconstructible]]) and `CopyAssignable`
5300
+ (Table  [[tab:copyassignable]]) types. In the range \[`first`, `last`\],
5301
+ `binary_op` shall neither modify elements nor invalidate iterators or
5302
+ subranges.[^13]
5303
+
5304
  *Effects:* Computes its result by initializing the accumulator `acc`
5305
  with the initial value `init` and then modifies it with `acc = acc + *i`
5306
  or `acc = binary_op(acc, *i)` for every iterator `i` in the range
5307
+ \[`first`, `last`) in order.[^14]
5308
 
5309
+ ### Reduce <a id="reduce">[[reduce]]</a>
5310
+
5311
+ ``` cpp
5312
+ template<class InputIterator>
5313
+ typename iterator_traits<InputIterator>::value_type
5314
+ reduce(InputIterator first, InputIterator last);
5315
+ ```
5316
+
5317
+ *Effects:* Equivalent to:
5318
+
5319
+ ``` cpp
5320
+ return reduce(first, last,
5321
+ typename iterator_traits<InputIterator>::value_type{});
5322
+ ```
5323
+
5324
+ ``` cpp
5325
+ template<class ExecutionPolicy, class ForwardIterator>
5326
+ typename iterator_traits<ForwardIterator>::value_type
5327
+ reduce(ExecutionPolicy&& exec,
5328
+ ForwardIterator first, ForwardIterator last);
5329
+ ```
5330
+
5331
+ *Effects:* Equivalent to:
5332
+
5333
+ ``` cpp
5334
+ return reduce(std::forward<ExecutionPolicy>(exec), first, last,
5335
+ typename iterator_traits<ForwardIterator>::value_type{});
5336
+ ```
5337
+
5338
+ ``` cpp
5339
+ template<class InputIterator, class T>
5340
+ T reduce(InputIterator first, InputIterator last, T init);
5341
+ ```
5342
+
5343
+ *Effects:* Equivalent to:
5344
+
5345
+ ``` cpp
5346
+ return reduce(first, last, init, plus<>());
5347
+ ```
5348
+
5349
+ ``` cpp
5350
+ template<class ExecutionPolicy, class ForwardIterator, class T>
5351
+ T reduce(ExecutionPolicy&& exec,
5352
+ ForwardIterator first, ForwardIterator last, T init);
5353
+ ```
5354
+
5355
+ *Effects:* Equivalent to:
5356
+
5357
+ ``` cpp
5358
+ return reduce(std::forward<ExecutionPolicy>(exec), first, last, init, plus<>());
5359
+ ```
5360
+
5361
+ ``` cpp
5362
+ template<class InputIterator, class T, class BinaryOperation>
5363
+ T reduce(InputIterator first, InputIterator last, T init,
5364
+ BinaryOperation binary_op);
5365
+ template<class ExecutionPolicy, class ForwardIterator, class T, class BinaryOperation>
5366
+ T reduce(ExecutionPolicy&& exec,
5367
+ ForwardIterator first, ForwardIterator last, T init,
5368
+ BinaryOperation binary_op);
5369
+ ```
5370
+
5371
+ *Requires:*
5372
+
5373
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
5374
+ - All of `binary_op(init, *first)`, `binary_op(*first, init)`,
5375
+ `binary_op(init, init)`, and `binary_op(*first, *first)` shall be
5376
+ convertible to `T`.
5377
+ - `binary_op` shall neither invalidate iterators or subranges, nor
5378
+ modify elements in the range \[`first`, `last`\].
5379
+
5380
+ *Returns:* *GENERALIZED_SUM*(binary_op, init, \*i, ...) for every `i` in
5381
+ \[`first`, `last`).
5382
+
5383
+ *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
5384
+
5385
+ [*Note 1*: The difference between `reduce` and `accumulate` is that
5386
+ `reduce` applies `binary_op` in an unspecified order, which yields a
5387
+ nondeterministic result for non-associative or non-commutative
5388
+ `binary_op` such as floating-point addition. — *end note*]
5389
 
5390
  ### Inner product <a id="inner.product">[[inner.product]]</a>
5391
 
5392
  ``` cpp
5393
  template <class InputIterator1, class InputIterator2, class T>
 
5399
  InputIterator2 first2, T init,
5400
  BinaryOperation1 binary_op1,
5401
  BinaryOperation2 binary_op2);
5402
  ```
5403
 
5404
+ *Requires:* `T` shall meet the requirements of `CopyConstructible`
5405
+ (Table  [[tab:copyconstructible]]) and `CopyAssignable`
5406
+ (Table  [[tab:copyassignable]]) types. In the ranges \[`first1`,
5407
+ `last1`\] and \[`first2`, `first2 + (last1 - first1)`\] `binary_op1` and
5408
+ `binary_op2` shall neither modify elements nor invalidate iterators or
5409
+ subranges.[^15]
5410
+
5411
  *Effects:* Computes its result by initializing the accumulator `acc`
5412
  with the initial value `init` and then modifying it with
5413
  `acc = acc + (*i1) * (*i2)` or
5414
  `acc = binary_op1(acc, binary_op2(*i1, *i2))` for every iterator `i1` in
5415
  the range \[`first1`, `last1`) and iterator `i2` in the range
5416
  \[`first2`, `first2 + (last1 - first1)`) in order.
5417
 
5418
+ ### Transform reduce <a id="transform.reduce">[[transform.reduce]]</a>
5419
+
5420
+ ``` cpp
5421
+ template <class InputIterator1, class InputIterator2, class T>
5422
+ T transform_reduce(InputIterator1 first1, InputIterator1 last1,
5423
+ InputIterator2 first2,
5424
+ T init);
5425
+ template <class ExecutionPolicy,
5426
+ class ForwardIterator1, class ForwardIterator2, class T>
5427
+ T transform_reduce(ExecutionPolicy&& exec,
5428
+ ForwardIterator1 first1, ForwardIterator1 last1,
5429
+ ForwardIterator2 first2,
5430
+ T init);
5431
+ ```
5432
+
5433
+ *Effects:* Equivalent to:
5434
+
5435
+ ``` cpp
5436
+ return transform_reduce(first1, last1, first2, init, plus<>(), multiplies<>());
5437
+ ```
5438
+
5439
+ ``` cpp
5440
+ template <class InputIterator1, class InputIterator2, class T,
5441
+ class BinaryOperation1, class BinaryOperation2>
5442
+ T transform_reduce(InputIterator1 first1, InputIterator1 last1,
5443
+ InputIterator2 first2,
5444
+ T init,
5445
+ BinaryOperation1 binary_op1,
5446
+ BinaryOperation2 binary_op2);
5447
+ template <class ExecutionPolicy,
5448
+ class ForwardIterator1, class ForwardIterator2, class T,
5449
+ class BinaryOperation1, class BinaryOperation2>
5450
+ T transform_reduce(ExecutionPolicy&& exec,
5451
+ ForwardIterator1 first1, ForwardIterator1 last1,
5452
+ ForwardIterator2 first2,
5453
+ T init,
5454
+ BinaryOperation1 binary_op1,
5455
+ BinaryOperation2 binary_op2);
5456
+ ```
5457
+
5458
+ *Requires:*
5459
+
5460
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
5461
+ - All of
5462
+ - `binary_op1(init, init)`,
5463
+ - `binary_op1(init, binary_op2(*first1, *first2))`,
5464
+ - `binary_op1(binary_op2(*first1, *first2), init)`, and
5465
+ - `binary_op1(binary_op2(*first1, *first2), binary_op2(*first1, *first2))`
5466
+
5467
+ shall be convertible to `T`.
5468
+ - Neither `binary_op1` nor `binary_op2` shall invalidate subranges, or
5469
+ modify elements in the ranges \[`first1`, `last1`\] and \[`first2`,
5470
+ `first2 + (last1 - first1)`\].
5471
+
5472
+ *Returns:*
5473
+
5474
+ ``` cpp
5475
+ GENERALIZED_SUM(binary_op1, init, binary_op2(*i, *(first2 + (i - first1))), ...)
5476
+ ```
5477
+
5478
+ for every iterator `i` in \[`first1`, `last1`).
5479
+
5480
+ *Complexity:* 𝑂(`last1 - first1`) applications each of `binary_op1` and
5481
+ `binary_op2`.
5482
+
5483
+ ``` cpp
5484
+ template<class InputIterator, class T,
5485
+ class BinaryOperation, class UnaryOperation>
5486
+ T transform_reduce(InputIterator first, InputIterator last, T init,
5487
+ BinaryOperation binary_op, UnaryOperation unary_op);
5488
+ template<class ExecutionPolicy,
5489
+ class ForwardIterator, class T,
5490
+ class BinaryOperation, class UnaryOperation>
5491
+ T transform_reduce(ExecutionPolicy&& exec,
5492
+ ForwardIterator first, ForwardIterator last,
5493
+ T init, BinaryOperation binary_op, UnaryOperation unary_op);
5494
+ ```
5495
+
5496
+ *Requires:*
5497
+
5498
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
5499
+ - All of
5500
+ - `binary_op(init, init)`,
5501
+ - `binary_op(init, unary_op(*first))`,
5502
+ - `binary_op(unary_op(*first), init)`, and
5503
+ - `binary_op(unary_op(*first), unary_op(*first))`
5504
+
5505
+ shall be convertible to `T`.
5506
+ - Neither `unary_op` nor `binary_op` shall invalidate subranges, or
5507
+ modify elements in the range \[`first`, `last`\].
5508
+
5509
+ *Returns:*
5510
+
5511
+ ``` cpp
5512
+ GENERALIZED_SUM(binary_op, init, unary_op(*i), ...)
5513
+ ```
5514
+
5515
+ for every iterator `i` in \[`first`, `last`).
5516
+
5517
+ *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
5518
+ `binary_op`.
5519
+
5520
+ [*Note 1*: `transform_reduce` does not apply `unary_op` to
5521
+ `init`. — *end note*]
5522
 
5523
  ### Partial sum <a id="partial.sum">[[partial.sum]]</a>
5524
 
5525
  ``` cpp
5526
  template <class InputIterator, class OutputIterator>
5527
  OutputIterator partial_sum(
5528
  InputIterator first, InputIterator last,
5529
  OutputIterator result);
5530
+ template <class InputIterator, class OutputIterator, class BinaryOperation>
 
5531
  OutputIterator partial_sum(
5532
  InputIterator first, InputIterator last,
5533
  OutputIterator result, BinaryOperation binary_op);
5534
  ```
5535
 
 
 
 
 
 
 
 
 
 
 
 
 
5536
  *Requires:* `InputIterator`’s value type shall be constructible from the
5537
  type of `*first`. The result of the expression `acc + *i` or
5538
  `binary_op(acc, *i)` shall be implicitly convertible to
5539
+ `InputIterator`’s value type. `acc` shall be
5540
+ writable ([[iterator.requirements.general]]) to the `result` output
5541
+ iterator. In the ranges \[`first`, `last`\] and \[`result`,
5542
+ `result + (last - first)`\] `binary_op` shall neither modify elements
5543
+ nor invalidate iterators or subranges.[^16]
5544
+
5545
+ *Effects:* For a non-empty range, the function creates an accumulator
5546
+ `acc` whose type is `InputIterator`’s value type, initializes it with
5547
+ `*first`, and assigns the result to `*result`. For every iterator `i` in
5548
+ \[`first + 1`, `last`) in order, `acc` is then modified by
5549
+ `acc = acc + *i` or `acc = binary_op(acc, *i)` and the result is
5550
+ assigned to `*(result + (i - first))`.
5551
+
5552
+ *Returns:* `result + (last - first)`.
5553
+
5554
+ *Complexity:* Exactly `(last - first) - 1` applications of the binary
5555
+ operation.
5556
+
5557
+ *Remarks:* `result` may be equal to `first`.
5558
+
5559
+ ### Exclusive scan <a id="exclusive.scan">[[exclusive.scan]]</a>
5560
+
5561
+ ``` cpp
5562
+ template<class InputIterator, class OutputIterator, class T>
5563
+ OutputIterator exclusive_scan(InputIterator first, InputIterator last,
5564
+ OutputIterator result,
5565
+ T init);
5566
+ ```
5567
+
5568
+ *Effects:* Equivalent to:
5569
+
5570
+ ``` cpp
5571
+ return exclusive_scan(first, last, result, init, plus<>());
5572
+ ```
5573
+
5574
+ ``` cpp
5575
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class T>
5576
+ ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec,
5577
+ ForwardIterator1 first, ForwardIterator1 last,
5578
+ ForwardIterator2 result,
5579
+ T init);
5580
+ ```
5581
+
5582
+ *Effects:* Equivalent to:
5583
+
5584
+ ``` cpp
5585
+ return exclusive_scan(std::forward<ExecutionPolicy>(exec),
5586
+ first, last, result, init, plus<>());
5587
+ ```
5588
+
5589
+ ``` cpp
5590
+ template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
5591
+ OutputIterator exclusive_scan(InputIterator first, InputIterator last,
5592
+ OutputIterator result,
5593
+ T init, BinaryOperation binary_op);
5594
+ template<class ExecutionPolicy,
5595
+ class ForwardIterator1, class ForwardIterator2, class T, class BinaryOperation>
5596
+ ForwardIterator2 exclusive_scan(ExecutionPolicy&& exec,
5597
+ ForwardIterator1 first, ForwardIterator1 last,
5598
+ ForwardIterator2 result,
5599
+ T init, BinaryOperation binary_op);
5600
+ ```
5601
+
5602
+ *Requires:*
5603
+
5604
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
5605
+ - All of `binary_op(init, init)`, `binary_op(init, *first)`, and
5606
+ `binary_op(*first, *first)` shall be convertible to `T`.
5607
+ - `binary_op` shall neither invalidate iterators or subranges, nor
5608
+ modify elements in the ranges \[`first`, `last`\] or \[`result`,
5609
+ `result + (last - first)`\].
5610
+
5611
+ *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
5612
+ through `result + K` the value of:
5613
+
5614
+ ``` cpp
5615
+ GENERALIZED_NONCOMMUTATIVE_SUM(
5616
+ binary_op, init, *(first + 0), *(first + 1), ..., *(first + K - 1))
5617
+ ```
5618
+
5619
+ *Returns:* The end of the resulting range beginning at `result`.
5620
+
5621
+ *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
5622
+
5623
+ *Remarks:* `result` may be equal to `first`.
5624
+
5625
+ [*Note 1*: The difference between `exclusive_scan` and `inclusive_scan`
5626
+ is that `exclusive_scan` excludes the `i`th input element from the `i`th
5627
+ sum. If `binary_op` is not mathematically associative, the behavior of
5628
+ `exclusive_scan` may be nondeterministic. — *end note*]
5629
+
5630
+ ### Inclusive scan <a id="inclusive.scan">[[inclusive.scan]]</a>
5631
+
5632
+ ``` cpp
5633
+ template<class InputIterator, class OutputIterator>
5634
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5635
+ OutputIterator result);
5636
+ ```
5637
+
5638
+ *Effects:* Equivalent to:
5639
+
5640
+ ``` cpp
5641
+ return inclusive_scan(first, last, result, plus<>());
5642
+ ```
5643
+
5644
+ ``` cpp
5645
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
5646
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec,
5647
+ ForwardIterator1 first, ForwardIterator1 last,
5648
+ ForwardIterator2 result);
5649
+ ```
5650
+
5651
+ *Effects:* Equivalent to:
5652
+
5653
+ ``` cpp
5654
+ return inclusive_scan(std::forward<ExecutionPolicy>(exec), first, last, result, plus<>());
5655
+ ```
5656
+
5657
+ ``` cpp
5658
+ template<class InputIterator, class OutputIterator, class BinaryOperation>
5659
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5660
+ OutputIterator result,
5661
+ BinaryOperation binary_op);
5662
+ template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
5663
+ class BinaryOperation>
5664
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec,
5665
+ ForwardIterator1 first, ForwardIterator1 last,
5666
+ ForwardIterator2 result,
5667
+ BinaryOperation binary_op);
5668
+
5669
+ template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
5670
+ OutputIterator inclusive_scan(InputIterator first, InputIterator last,
5671
+ OutputIterator result,
5672
+ BinaryOperation binary_op, T init);
5673
+ template<class ExecutionPolicy,
5674
+ class ForwardIterator1, class ForwardIterator2, class BinaryOperation, class T>
5675
+ ForwardIterator2 inclusive_scan(ExecutionPolicy&& exec,
5676
+ ForwardIterator1 first, ForwardIterator1 last,
5677
+ ForwardIterator2 result,
5678
+ BinaryOperation binary_op, T init);
5679
+ ```
5680
+
5681
+ *Requires:*
5682
+
5683
+ - If `init` is provided, `T` shall be `MoveConstructible`
5684
+ (Table  [[tab:moveconstructible]]); otherwise, `ForwardIterator1`’s
5685
+ value type shall be `MoveConstructible`.
5686
+ - If `init` is provided, all of `binary_op(init, init)`,
5687
+ `binary_op(init, *first)`, and `binary_op(*first, *first)` shall be
5688
+ convertible to `T`; otherwise, `binary_op(*first, *first)` shall be
5689
+ convertible to `ForwardIterator1`’s value type.
5690
+ - `binary_op` shall neither invalidate iterators or subranges, nor
5691
+ modify elements in the ranges \[`first`, `last`\] or \[`result`,
5692
+ `result + (last - first)`\].
5693
+
5694
+ *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
5695
+ through `result + K` the value of
5696
+
5697
+ - *GENERALIZED_NONCOMMUTATIVE_SUM*(
5698
+     binary_op, init, \*(first + 0), \*(first + 1), ..., \*(first +
5699
+ K))
5700
+ if `init` is provided, or
5701
+ - *GENERALIZED_NONCOMMUTATIVE_SUM*(
5702
+     binary_op, \*(first + 0), \*(first + 1), ..., \*(first + K))
5703
+ otherwise.
5704
+
5705
+ *Returns:* The end of the resulting range beginning at `result`.
5706
+
5707
+ *Complexity:* 𝑂(`last - first`) applications of `binary_op`.
5708
 
5709
  *Remarks:* `result` may be equal to `first`.
5710
 
5711
+ [*Note 1*: The difference between `exclusive_scan` and `inclusive_scan`
5712
+ is that `inclusive_scan` includes the `i`th input element in the `i`th
5713
+ sum. If `binary_op` is not mathematically associative, the behavior of
5714
+ `inclusive_scan` may be nondeterministic. — *end note*]
5715
+
5716
+ ### Transform exclusive scan <a id="transform.exclusive.scan">[[transform.exclusive.scan]]</a>
5717
+
5718
+ ``` cpp
5719
+ template<class InputIterator, class OutputIterator, class T,
5720
+ class BinaryOperation, class UnaryOperation>
5721
+ OutputIterator transform_exclusive_scan(InputIterator first, InputIterator last,
5722
+ OutputIterator result,
5723
+ T init,
5724
+ BinaryOperation binary_op,
5725
+ UnaryOperation unary_op);
5726
+ template<class ExecutionPolicy,
5727
+ class ForwardIterator1, class ForwardIterator2, class T,
5728
+ class BinaryOperation, class UnaryOperation>
5729
+ ForwardIterator2 transform_exclusive_scan(ExecutionPolicy&& exec,
5730
+ ForwardIterator1 first, ForwardIterator1 last,
5731
+ ForwardIterator2 result,
5732
+ T init,
5733
+ BinaryOperation binary_op,
5734
+ UnaryOperation unary_op);
5735
+ ```
5736
+
5737
+ *Requires:*
5738
+
5739
+ - `T` shall be `MoveConstructible` (Table  [[tab:moveconstructible]]).
5740
+ - All of
5741
+ - `binary_op(init, init)`,
5742
+ - `binary_op(init, unary_op(*first))`, and
5743
+ - `binary_op(unary_op(*first), unary_op(*first))`
5744
+
5745
+ shall be convertible to `T`.
5746
+ - Neither `unary_op` nor `binary_op` shall invalidate iterators or
5747
+ subranges, or modify elements in the ranges \[`first`, `last`\] or
5748
+ \[`result`, `result + (last - first)`\].
5749
+
5750
+ *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
5751
+ through `result + K` the value of:
5752
+
5753
+ ``` cpp
5754
+ GENERALIZED_NONCOMMUTATIVE_SUM(
5755
+ binary_op, init,
5756
+ unary_op(*(first + 0)), unary_op(*(first + 1)), ..., unary_op(*(first + K - 1)))
5757
+ ```
5758
+
5759
+ *Returns:* The end of the resulting range beginning at `result`.
5760
+
5761
+ *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
5762
+ `binary_op`.
5763
+
5764
+ *Remarks:* `result` may be equal to `first`.
5765
+
5766
+ [*Note 1*: The difference between `transform_exclusive_scan` and
5767
+ `transform_inclusive_scan` is that `transform_exclusive_scan` excludes
5768
+ the iᵗʰ input element from the iᵗʰ sum. If `binary_op` is not
5769
+ mathematically associative, the behavior of `transform_exclusive_scan`
5770
+ may be nondeterministic. `transform_exclusive_scan` does not apply
5771
+ `unary_op` to `init`. — *end note*]
5772
+
5773
+ ### Transform inclusive scan <a id="transform.inclusive.scan">[[transform.inclusive.scan]]</a>
5774
+
5775
+ ``` cpp
5776
+ template<class InputIterator, class OutputIterator,
5777
+ class BinaryOperation, class UnaryOperation>
5778
+ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
5779
+ OutputIterator result,
5780
+ BinaryOperation binary_op,
5781
+ UnaryOperation unary_op);
5782
+ template<class ExecutionPolicy,
5783
+ class ForwardIterator1, class ForwardIterator2,
5784
+ class BinaryOperation, class UnaryOperation>
5785
+ ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec,
5786
+ ForwardIterator1 first, ForwardIterator1 last,
5787
+ ForwardIterator2 result,
5788
+ BinaryOperation binary_op,
5789
+ UnaryOperation unary_op);
5790
+ template<class InputIterator, class OutputIterator,
5791
+ class BinaryOperation, class UnaryOperation, class T>
5792
+ OutputIterator transform_inclusive_scan(InputIterator first, InputIterator last,
5793
+ OutputIterator result,
5794
+ BinaryOperation binary_op,
5795
+ UnaryOperation unary_op,
5796
+ T init);
5797
+ template<class ExecutionPolicy,
5798
+ class ForwardIterator1, class ForwardIterator2,
5799
+ class BinaryOperation, class UnaryOperation, class T>
5800
+ ForwardIterator2 transform_inclusive_scan(ExecutionPolicy&& exec,
5801
+ ForwardIterator1 first, ForwardIterator1 last,
5802
+ ForwardIterator2 result,
5803
+ BinaryOperation binary_op,
5804
+ UnaryOperation unary_op,
5805
+ T init);
5806
+ ```
5807
+
5808
+ *Requires:*
5809
+
5810
+ - If `init` is provided, `T` shall be `MoveConstructible`
5811
+ (Table  [[tab:moveconstructible]]); otherwise, `ForwardIterator1`’s
5812
+ value type shall be `MoveConstructible`.
5813
+ - If `init` is provided, all of
5814
+ - `binary_op(init, init)`,
5815
+ - `binary_op(init, unary_op(*first))`, and
5816
+ - `binary_op(unary_op(*first), unary_op(*first))`
5817
+
5818
+ shall be convertible to `T`; otherwise,
5819
+ `binary_op(unary_op(*first), unary_op(*first))` shall be convertible
5820
+ to `ForwardIterator1`’s value type.
5821
+ - Neither `unary_op` nor `binary_op` shall invalidate iterators or
5822
+ subranges, nor modify elements in the ranges \[`first`, `last`\] or
5823
+ \[`result`, `result + (last - first)`\].
5824
+
5825
+ *Effects:* For each integer `K` in \[`0`, `last - first`) assigns
5826
+ through `result + K` the value of
5827
+
5828
+ - *GENERALIZED_NONCOMMUTATIVE_SUM*(
5829
+     binary_op, init,
5830
+     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
5831
+ unary_op(\*(first + K)))
5832
+ if `init` is provided, or
5833
+ - *GENERALIZED_NONCOMMUTATIVE_SUM*(
5834
+     binary_op,
5835
+     unary_op(\*(first + 0)), unary_op(\*(first + 1)), ...,
5836
+ unary_op(\*(first + K)))
5837
+ otherwise.
5838
+
5839
+ *Returns:* The end of the resulting range beginning at `result`.
5840
+
5841
+ *Complexity:* 𝑂(`last - first`) applications each of `unary_op` and
5842
+ `binary_op`.
5843
+
5844
+ *Remarks:* `result` may be equal to `first`.
5845
+
5846
+ [*Note 1*: The difference between `transform_exclusive_scan` and
5847
+ `transform_inclusive_scan` is that `transform_inclusive_scan` includes
5848
+ the iᵗʰ input element in the iᵗʰ sum. If `binary_op` is not
5849
+ mathematically associative, the behavior of `transform_inclusive_scan`
5850
+ may be nondeterministic. `transform_inclusive_scan` does not apply
5851
+ `unary_op` to `init`. — *end note*]
5852
+
5853
  ### Adjacent difference <a id="adjacent.difference">[[adjacent.difference]]</a>
5854
 
5855
  ``` cpp
5856
  template <class InputIterator, class OutputIterator>
5857
+ OutputIterator
5858
+ adjacent_difference(InputIterator first, InputIterator last,
5859
  OutputIterator result);
5860
+ template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2>
5861
+ ForwardIterator2
5862
+ adjacent_difference(ExecutionPolicy&& exec,
5863
+ ForwardIterator1 first, ForwardIterator1 last,
5864
+ ForwardIterator2 result);
5865
+
5866
  template <class InputIterator, class OutputIterator, class BinaryOperation>
5867
+ OutputIterator
5868
+ adjacent_difference(InputIterator first, InputIterator last,
5869
  OutputIterator result,
5870
  BinaryOperation binary_op);
5871
+ template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
5872
+ class BinaryOperation>
5873
+ ForwardIterator2
5874
+ adjacent_difference(ExecutionPolicy&& exec,
5875
+ ForwardIterator1 first, ForwardIterator1 last,
5876
+ ForwardIterator2 result,
5877
+ BinaryOperation binary_op);
5878
  ```
5879
 
5880
+ *Requires:*
5881
+
5882
+ - For the overloads with no `ExecutionPolicy`, `InputIterator`’s value
5883
+ type shall be `MoveAssignable` (Table  [[tab:moveassignable]]) and
5884
+ shall be constructible from the type of `*first`. `acc` (defined
5885
+ below) shall be writable ([[iterator.requirements.general]]) to the
5886
+ `result` output iterator. The result of the expression `val - acc` or
5887
+ `binary_op(val, acc)` shall be writable to the `result` output
5888
+ iterator.
5889
+ - For the overloads with an `ExecutionPolicy`, the value type of
5890
+ `ForwardIterator1` shall be `CopyConstructible`
5891
+ (Table  [[tab:copyconstructible]]), constructible from the expression
5892
+ `*first - *first` or `binary_op(*first, *first)`, and assignable to
5893
+ the value type of `ForwardIterator2`.
5894
+ - For all overloads, in the ranges \[`first`, `last`\] and \[`result`,
5895
+ `result + (last - first)`\], `binary_op` shall neither modify elements
5896
+ nor invalidate iterators or subranges.[^17]
5897
+
5898
+ *Effects:* For the overloads with no `ExecutionPolicy` and a non-empty
5899
+ range, the function creates an accumulator `acc` whose type is
5900
+ `InputIterator`’s value type, initializes it with `*first`, and assigns
5901
+ the result to `*result`. For every iterator `i` in \[`first + 1`,
5902
+ `last`) in order, creates an object `val` whose type is
5903
  `InputIterator`’s value type, initializes it with `*i`, computes
5904
  `val - acc` or `binary_op(val, acc)`, assigns the result to
5905
  `*(result + (i - first))`, and move assigns from `val` to `acc`.
5906
 
5907
+ For the overloads with an `ExecutionPolicy` and a non-empty range, first
5908
+ the function creates an object whose type is `ForwardIterator1`’s value
5909
+ type, initializes it with `*first`, and assigns the result to `*result`.
5910
+ Then for every `d` in \[`1`, `last - first - 1`\], creates an object
5911
+ `val` whose type is `ForwardIterator1`’s value type, initializes it with
5912
+ `*(first + d) - *(first + d - 1)` or
5913
+ `binary_op(*(first + d), *(first + d - 1))`, and assigns the result to
5914
+ `*(result + d)`.
 
5915
 
5916
  *Returns:* `result + (last - first)`.
5917
 
5918
  *Complexity:* Exactly `(last - first) - 1` applications of the binary
5919
  operation.
5920
 
5921
+ *Remarks:* For the overloads with no `ExecutionPolicy`, `result` may be
5922
+ equal to `first`. For the overloads with an `ExecutionPolicy`, the
5923
+ ranges \[`first`, `last`) and \[`result`, `result + (last - first)`)
5924
+ shall not overlap.
5925
+
5926
  ### Iota <a id="numeric.iota">[[numeric.iota]]</a>
5927
 
5928
  ``` cpp
5929
  template <class ForwardIterator, class T>
5930
  void iota(ForwardIterator first, ForwardIterator last, T value);
 
5937
  \[`first`, `last`), assigns `*i = value` and increments `value` as if by
5938
  `++value`.
5939
 
5940
  *Complexity:* Exactly `last - first` increments and assignments.
5941
 
5942
+ ### Greatest common divisor <a id="numeric.ops.gcd">[[numeric.ops.gcd]]</a>
5943
 
5944
+ ``` cpp
5945
+ template <class M, class N>
5946
+ constexpr common_type_t<M,N> gcd(M m, N n);
5947
+ ```
5948
 
5949
+ *Requires:* `|m|` and `|n|` shall be representable as a value of
5950
+ `common_type_t<M, N>`.
5951
 
5952
+ [*Note 1*: These requirements ensure, for example, that
5953
+ `gcd(m, m) = |m|` is representable as a value of type
5954
+ `M`. — *end note*]
5955
 
5956
+ *Remarks:* If either `M` or `N` is not an integer type, or if either is
5957
+ cv `bool`, the program is ill-formed.
 
5958
 
5959
+ *Returns:* Zero when `m` and `n` are both zero. Otherwise, returns the
5960
+ greatest common divisor of `|m|` and `|n|`.
 
 
 
 
 
 
5961
 
5962
+ *Throws:* Nothing.
 
 
5963
 
5964
+ ### Least common multiple <a id="numeric.ops.lcm">[[numeric.ops.lcm]]</a>
5965
 
5966
  ``` cpp
5967
+ template <class M, class N>
5968
+ constexpr common_type_t<M,N> lcm(M m, N n);
 
 
5969
  ```
5970
 
5971
+ *Requires:* `|m|` and `|n|` shall be representable as a value of
5972
+ `common_type_t<M, N>`. The least common multiple of `|m|` and `|n|`
5973
+ shall be representable as a value of type `common_type_t<M,N>`.
5974
 
5975
+ *Remarks:* If either `M` or `N` is not an integer type, or if either is
5976
+ cv `bool` the program is ill-formed.
5977
 
5978
+ *Returns:* Zero when either `m` or `n` is zero. Otherwise, returns the
5979
+ least common multiple of `|m|` and `|n|`.
5980
+
5981
+ *Throws:* Nothing.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5982
 
5983
+ ## Mathematical functions for floating-point types <a id="c.math">[[c.math]]</a>
5984
+
5985
+ ### Header `<cmath>` synopsis <a id="cmath.syn">[[cmath.syn]]</a>
 
5986
 
5987
  ``` cpp
5988
+ namespace std {
5989
+ using float_t = see below;
5990
+ using double_t = see below;
5991
+ }
5992
+
5993
+ #define HUGE_VAL see below
5994
+ #define HUGE_VALF see below
5995
+ #define HUGE_VALL see below
5996
+ #define INFINITY see below
5997
+ #define NAN see below
5998
+ #define FP_INFINITE see below
5999
+ #define FP_NAN see below
6000
+ #define FP_NORMAL see below
6001
+ #define FP_SUBNORMAL see below
6002
+ #define FP_ZERO see below
6003
+ #define FP_FAST_FMA see below
6004
+ #define FP_FAST_FMAF see below
6005
+ #define FP_FAST_FMAL see below
6006
+ #define FP_ILOGB0 see below
6007
+ #define FP_ILOGBNAN see below
6008
+ #define MATH_ERRNO see below
6009
+ #define MATH_ERREXCEPT see below
6010
+
6011
+ #define math_errhandling see below
6012
+
6013
+ namespace std {
6014
+ float acos(float x); // see [library.c]
6015
+ double acos(double x);
6016
+ long double acos(long double x); // see [library.c]
6017
+ float acosf(float x);
6018
+ long double acosl(long double x);
6019
+
6020
+ float asin(float x); // see [library.c]
6021
+ double asin(double x);
6022
+ long double asin(long double x); // see [library.c]
6023
+ float asinf(float x);
6024
+ long double asinl(long double x);
6025
+
6026
+ float atan(float x); // see [library.c]
6027
+ double atan(double x);
6028
+ long double atan(long double x); // see [library.c]
6029
+ float atanf(float x);
6030
+ long double atanl(long double x);
6031
+
6032
+ float atan2(float y, float x); // see [library.c]
6033
+ double atan2(double y, double x);
6034
+ long double atan2(long double y, long double x); // see [library.c]
6035
+ float atan2f(float y, float x);
6036
+ long double atan2l(long double y, long double x);
6037
+
6038
+ float cos(float x); // see [library.c]
6039
+ double cos(double x);
6040
+ long double cos(long double x); // see [library.c]
6041
+ float cosf(float x);
6042
+ long double cosl(long double x);
6043
+
6044
+ float sin(float x); // see [library.c]
6045
+ double sin(double x);
6046
+ long double sin(long double x); // see [library.c]
6047
+ float sinf(float x);
6048
+ long double sinl(long double x);
6049
+
6050
+ float tan(float x); // see [library.c]
6051
+ double tan(double x);
6052
+ long double tan(long double x); // see [library.c]
6053
+ float tanf(float x);
6054
+ long double tanl(long double x);
6055
+
6056
+ float acosh(float x); // see [library.c]
6057
+ double acosh(double x);
6058
+ long double acosh(long double x); // see [library.c]
6059
+ float acoshf(float x);
6060
+ long double acoshl(long double x);
6061
+
6062
+ float asinh(float x); // see [library.c]
6063
+ double asinh(double x);
6064
+ long double asinh(long double x); // see [library.c]
6065
+ float asinhf(float x);
6066
+ long double asinhl(long double x);
6067
+
6068
+ float atanh(float x); // see [library.c]
6069
+ double atanh(double x);
6070
+ long double atanh(long double x); // see [library.c]
6071
+ float atanhf(float x);
6072
+ long double atanhl(long double x);
6073
+
6074
+ float cosh(float x); // see [library.c]
6075
+ double cosh(double x);
6076
+ long double cosh(long double x); // see [library.c]
6077
+ float coshf(float x);
6078
+ long double coshl(long double x);
6079
+
6080
+ float sinh(float x); // see [library.c]
6081
+ double sinh(double x);
6082
+ long double sinh(long double x); // see [library.c]
6083
+ float sinhf(float x);
6084
+ long double sinhl(long double x);
6085
+
6086
+ float tanh(float x); // see [library.c]
6087
+ double tanh(double x);
6088
+ long double tanh(long double x); // see [library.c]
6089
+ float tanhf(float x);
6090
+ long double tanhl(long double x);
6091
+
6092
+ float exp(float x); // see [library.c]
6093
+ double exp(double x);
6094
+ long double exp(long double x); // see [library.c]
6095
+ float expf(float x);
6096
+ long double expl(long double x);
6097
+
6098
+ float exp2(float x); // see [library.c]
6099
+ double exp2(double x);
6100
+ long double exp2(long double x); // see [library.c]
6101
+ float exp2f(float x);
6102
+ long double exp2l(long double x);
6103
+
6104
+ float expm1(float x); // see [library.c]
6105
+ double expm1(double x);
6106
+ long double expm1(long double x); // see [library.c]
6107
+ float expm1f(float x);
6108
+ long double expm1l(long double x);
6109
+
6110
+ float frexp(float value, int* exp); // see [library.c]
6111
+ double frexp(double value, int* exp);
6112
+ long double frexp(long double value, int* exp); // see [library.c]
6113
+ float frexpf(float value, int* exp);
6114
+ long double frexpl(long double value, int* exp);
6115
+
6116
+ int ilogb(float x); // see [library.c]
6117
+ int ilogb(double x);
6118
+ int ilogb(long double x); // see [library.c]
6119
+ int ilogbf(float x);
6120
+ int ilogbl(long double x);
6121
+
6122
+ float ldexp(float x, int exp); // see [library.c]
6123
+ double ldexp(double x, int exp);
6124
+ long double ldexp(long double x, int exp); // see [library.c]
6125
+ float ldexpf(float x, int exp);
6126
+ long double ldexpl(long double x, int exp);
6127
+
6128
+ float log(float x); // see [library.c]
6129
+ double log(double x);
6130
+ long double log(long double x); // see [library.c]
6131
+ float logf(float x);
6132
+ long double logl(long double x);
6133
+
6134
+ float log10(float x); // see [library.c]
6135
+ double log10(double x);
6136
+ long double log10(long double x); // see [library.c]
6137
+ float log10f(float x);
6138
+ long double log10l(long double x);
6139
+
6140
+ float log1p(float x); // see [library.c]
6141
+ double log1p(double x);
6142
+ long double log1p(long double x); // see [library.c]
6143
+ float log1pf(float x);
6144
+ long double log1pl(long double x);
6145
+
6146
+ float log2(float x); // see [library.c]
6147
+ double log2(double x);
6148
+ long double log2(long double x); // see [library.c]
6149
+ float log2f(float x);
6150
+ long double log2l(long double x);
6151
+
6152
+ float logb(float x); // see [library.c]
6153
+ double logb(double x);
6154
+ long double logb(long double x); // see [library.c]
6155
+ float logbf(float x);
6156
+ long double logbl(long double x);
6157
+
6158
+ float modf(float value, float* iptr); // see [library.c]
6159
+ double modf(double value, double* iptr);
6160
+ long double modf(long double value, long double* iptr); // see [library.c]
6161
+ float modff(float value, float* iptr);
6162
+ long double modfl(long double value, long double* iptr);
6163
+
6164
+ float scalbn(float x, int n); // see [library.c]
6165
+ double scalbn(double x, int n);
6166
+ long double scalbn(long double x, int n); // see [library.c]
6167
+ float scalbnf(float x, int n);
6168
+ long double scalbnl(long double x, int n);
6169
+
6170
+ float scalbln(float x, long int n); // see [library.c]
6171
+ double scalbln(double x, long int n);
6172
+ long double scalbln(long double x, long int n); // see [library.c]
6173
+ float scalblnf(float x, long int n);
6174
+ long double scalblnl(long double x, long int n);
6175
+
6176
+ float cbrt(float x); // see [library.c]
6177
+ double cbrt(double x);
6178
+ long double cbrt(long double x); // see [library.c]
6179
+ float cbrtf(float x);
6180
+ long double cbrtl(long double x);
6181
+
6182
+ // [c.math.abs], absolute values
6183
+ int abs(int j);
6184
+ long int abs(long int j);
6185
+ long long int abs(long long int j);
6186
+ float abs(float j);
6187
+ double abs(double j);
6188
+ long double abs(long double j);
6189
+
6190
+ float fabs(float x); // see [library.c]
6191
+ double fabs(double x);
6192
+ long double fabs(long double x); // see [library.c]
6193
+ float fabsf(float x);
6194
+ long double fabsl(long double x);
6195
+
6196
+ float hypot(float x, float y); // see [library.c]
6197
+ double hypot(double x, double y);
6198
+ long double hypot(double x, double y); // see [library.c]
6199
+ float hypotf(float x, float y);
6200
+ long double hypotl(long double x, long double y);
6201
+
6202
+ // [c.math.hypot3], three-dimensional hypotenuse
6203
+ float hypot(float x, float y, float z);
6204
+ double hypot(double x, double y, double z);
6205
+ long double hypot(long double x, long double y, long double z);
6206
+
6207
+ float pow(float x, float y); // see [library.c]
6208
+ double pow(double x, double y);
6209
+ long double pow(long double x, long double y); // see [library.c]
6210
+ float powf(float x, float y);
6211
+ long double powl(long double x, long double y);
6212
+
6213
+ float sqrt(float x); // see [library.c]
6214
+ double sqrt(double x);
6215
+ long double sqrt(long double x); // see [library.c]
6216
+ float sqrtf(float x);
6217
+ long double sqrtl(long double x);
6218
+
6219
+ float erf(float x); // see [library.c]
6220
+ double erf(double x);
6221
+ long double erf(long double x); // see [library.c]
6222
+ float erff(float x);
6223
+ long double erfl(long double x);
6224
+
6225
+ float erfc(float x); // see [library.c]
6226
+ double erfc(double x);
6227
+ long double erfc(long double x); // see [library.c]
6228
+ float erfcf(float x);
6229
+ long double erfcl(long double x);
6230
+
6231
+ float lgamma(float x); // see [library.c]
6232
+ double lgamma(double x);
6233
+ long double lgamma(long double x); // see [library.c]
6234
+ float lgammaf(float x);
6235
+ long double lgammal(long double x);
6236
+
6237
+ float tgamma(float x); // see [library.c]
6238
+ double tgamma(double x);
6239
+ long double tgamma(long double x); // see [library.c]
6240
+ float tgammaf(float x);
6241
+ long double tgammal(long double x);
6242
+
6243
+ float ceil(float x); // see [library.c]
6244
+ double ceil(double x);
6245
+ long double ceil(long double x); // see [library.c]
6246
+ float ceilf(float x);
6247
+ long double ceill(long double x);
6248
+
6249
+ float floor(float x); // see [library.c]
6250
+ double floor(double x);
6251
+ long double floor(long double x); // see [library.c]
6252
+ float floorf(float x);
6253
+ long double floorl(long double x);
6254
+
6255
+ float nearbyint(float x); // see [library.c]
6256
+ double nearbyint(double x);
6257
+ long double nearbyint(long double x); // see [library.c]
6258
+ float nearbyintf(float x);
6259
+ long double nearbyintl(long double x);
6260
+
6261
+ float rint(float x); // see [library.c]
6262
+ double rint(double x);
6263
+ long double rint(long double x); // see [library.c]
6264
+ float rintf(float x);
6265
+ long double rintl(long double x);
6266
+
6267
+ long int lrint(float x); // see [library.c]
6268
+ long int lrint(double x);
6269
+ long int lrint(long double x); // see [library.c]
6270
+ long int lrintf(float x);
6271
+ long int lrintl(long double x);
6272
+
6273
+ long long int llrint(float x); // see [library.c]
6274
+ long long int llrint(double x);
6275
+ long long int llrint(long double x); // see [library.c]
6276
+ long long int llrintf(float x);
6277
+ long long int llrintl(long double x);
6278
+
6279
+ float round(float x); // see [library.c]
6280
+ double round(double x);
6281
+ long double round(long double x); // see [library.c]
6282
+ float roundf(float x);
6283
+ long double roundl(long double x);
6284
+
6285
+ long int lround(float x); // see [library.c]
6286
+ long int lround(double x);
6287
+ long int lround(long double x); // see [library.c]
6288
+ long int lroundf(float x);
6289
+ long int lroundl(long double x);
6290
+
6291
+ long long int llround(float x); // see [library.c]
6292
+ long long int llround(double x);
6293
+ long long int llround(long double x); // see [library.c]
6294
+ long long int llroundf(float x);
6295
+ long long int llroundl(long double x);
6296
+
6297
+ float trunc(float x); // see [library.c]
6298
+ double trunc(double x);
6299
+ long double trunc(long double x); // see [library.c]
6300
+ float truncf(float x);
6301
+ long double truncl(long double x);
6302
+
6303
+ float fmod(float x, float y); // see [library.c]
6304
+ double fmod(double x, double y);
6305
+ long double fmod(long double x, long double y); // see [library.c]
6306
+ float fmodf(float x, float y);
6307
+ long double fmodl(long double x, long double y);
6308
+
6309
+ float remainder(float x, float y); // see [library.c]
6310
+ double remainder(double x, double y);
6311
+ long double remainder(long double x, long double y); // see [library.c]
6312
+ float remainderf(float x, float y);
6313
+ long double remainderl(long double x, long double y);
6314
+
6315
+ float remquo(float x, float y, int* quo); // see [library.c]
6316
+ double remquo(double x, double y, int* quo);
6317
+ long double remquo(long double x, long double y, int* quo); // see [library.c]
6318
+ float remquof(float x, float y, int* quo);
6319
+ long double remquol(long double x, long double y, int* quo);
6320
+
6321
+ float copysign(float x, float y); // see [library.c]
6322
+ double copysign(double x, double y);
6323
+ long double copysign(long double x, long double y); // see [library.c]
6324
+ float copysignf(float x, float y);
6325
+ long double copysignl(long double x, long double y);
6326
+
6327
+ double nan(const char* tagp);
6328
+ float nanf(const char* tagp);
6329
+ long double nanl(const char* tagp);
6330
+
6331
+ float nextafter(float x, float y); // see [library.c]
6332
+ double nextafter(double x, double y);
6333
+ long double nextafter(long double x, long double y); // see [library.c]
6334
+ float nextafterf(float x, float y);
6335
+ long double nextafterl(long double x, long double y);
6336
+
6337
+ float nexttoward(float x, long double y); // see [library.c]
6338
+ double nexttoward(double x, long double y);
6339
+ long double nexttoward(long double x, long double y); // see [library.c]
6340
+ float nexttowardf(float x, long double y);
6341
+ long double nexttowardl(long double x, long double y);
6342
+
6343
+ float fdim(float x, float y); // see [library.c]
6344
+ double fdim(double x, double y);
6345
+ long double fdim(long double x, long double y); // see [library.c]
6346
+ float fdimf(float x, float y);
6347
+ long double fdiml(long double x, long double y);
6348
+
6349
+ float fmax(float x, float y); // see [library.c]
6350
+ double fmax(double x, double y);
6351
+ long double fmax(long double x, long double y); // see [library.c]
6352
+ float fmaxf(float x, float y);
6353
+ long double fmaxl(long double x, long double y);
6354
+
6355
+ float fmin(float x, float y); // see [library.c]
6356
+ double fmin(double x, double y);
6357
+ long double fmin(long double x, long double y); // see [library.c]
6358
+ float fminf(float x, float y);
6359
+ long double fminl(long double x, long double y);
6360
+
6361
+ float fma(float x, float y, float z); // see [library.c]
6362
+ double fma(double x, double y, double z);
6363
+ long double fma(long double x, long double y, long double z); // see [library.c]
6364
+ float fmaf(float x, float y, float z);
6365
+ long double fmal(long double x, long double y, long double z);
6366
+
6367
+ // [c.math.fpclass], classification / comparison functions
6368
  int fpclassify(float x);
 
 
 
 
 
 
 
 
 
 
 
 
 
6369
  int fpclassify(double x);
 
 
 
 
 
 
 
 
 
 
 
 
 
6370
  int fpclassify(long double x);
6371
+
6372
+ int isfinite(float x);
6373
+ int isfinite(double x);
6374
+ int isfinite(long double x);
6375
+
6376
+ int isinf(float x);
6377
+ int isinf(double x);
6378
+ int isinf(long double x);
6379
+
6380
+ int isnan(float x);
6381
+ int isnan(double x);
6382
+ int isnan(long double x);
6383
+
6384
+ int isnormal(float x);
6385
+ int isnormal(double x);
6386
+ int isnormal(long double x);
6387
+
6388
+ int signbit(float x);
6389
+ int signbit(double x);
6390
+ int signbit(long double x);
6391
+
6392
+ int isgreater(float x, float y);
6393
+ int isgreater(double x, double y);
6394
+ int isgreater(long double x, long double y);
6395
+
6396
+ int isgreaterequal(float x, float y);
6397
+ int isgreaterequal(double x, double y);
6398
+ int isgreaterequal(long double x, long double y);
6399
+
6400
+ int isless(float x, float y);
6401
+ int isless(double x, double y);
6402
+ int isless(long double x, long double y);
6403
+
6404
+ int islessequal(float x, float y);
6405
+ int islessequal(double x, double y);
6406
+ int islessequal(long double x, long double y);
6407
+
6408
+ int islessgreater(float x, float y);
6409
+ int islessgreater(double x, double y);
6410
+ int islessgreater(long double x, long double y);
6411
+
6412
+ int isunordered(float x, float y);
6413
+ int isunordered(double x, double y);
6414
+ int isunordered(long double x, long double y);
6415
+
6416
+ // [sf.cmath], mathematical special functions
6417
+
6418
+ // [sf.cmath.assoc_laguerre], associated Laguerre polynomials
6419
+ double assoc_laguerre(unsigned n, unsigned m, double x);
6420
+ float assoc_laguerref(unsigned n, unsigned m, float x);
6421
+ long double assoc_laguerrel(unsigned n, unsigned m, long double x);
6422
+
6423
+ // [sf.cmath.assoc_legendre], associated Legendre functions
6424
+ double assoc_legendre(unsigned l, unsigned m, double x);
6425
+ float assoc_legendref(unsigned l, unsigned m, float x);
6426
+ long double assoc_legendrel(unsigned l, unsigned m, long double x);
6427
+
6428
+ // [sf.cmath.beta], beta function
6429
+ double beta(double x, double y);
6430
+ float betaf(float x, float y);
6431
+ long double betal(long double x, long double y);
6432
+
6433
+ // [sf.cmath.comp_ellint_1], complete elliptic integral of the first kind
6434
+ double comp_ellint_1(double k);
6435
+ float comp_ellint_1f(float k);
6436
+ long double comp_ellint_1l(long double k);
6437
+
6438
+ // [sf.cmath.comp_ellint_2], complete elliptic integral of the second kind
6439
+ double comp_ellint_2(double k);
6440
+ float comp_ellint_2f(float k);
6441
+ long double comp_ellint_2l(long double k);
6442
+
6443
+ // [sf.cmath.comp_ellint_3], complete elliptic integral of the third kind
6444
+ double comp_ellint_3(double k, double nu);
6445
+ float comp_ellint_3f(float k, float nu);
6446
+ long double comp_ellint_3l(long double k, long double nu);
6447
+
6448
+ // [sf.cmath.cyl_bessel_i], regular modified cylindrical Bessel functions
6449
+ double cyl_bessel_i(double nu, double x);
6450
+ float cyl_bessel_if(float nu, float x);
6451
+ long double cyl_bessel_il(long double nu, long double x);
6452
+
6453
+ // [sf.cmath.cyl_bessel_j], cylindrical Bessel functions of the first kind
6454
+ double cyl_bessel_j(double nu, double x);
6455
+ float cyl_bessel_jf(float nu, float x);
6456
+ long double cyl_bessel_jl(long double nu, long double x);
6457
+
6458
+ // [sf.cmath.cyl_bessel_k], irregular modified cylindrical Bessel functions
6459
+ double cyl_bessel_k(double nu, double x);
6460
+ float cyl_bessel_kf(float nu, float x);
6461
+ long double cyl_bessel_kl(long double nu, long double x);
6462
+
6463
+ // [sf.cmath.cyl_neumann], cylindrical Neumann functions;
6464
+ // cylindrical Bessel functions of the second kind
6465
+ double cyl_neumann(double nu, double x);
6466
+ float cyl_neumannf(float nu, float x);
6467
+ long double cyl_neumannl(long double nu, long double x);
6468
+
6469
+ // [sf.cmath.ellint_1], incomplete elliptic integral of the first kind
6470
+ double ellint_1(double k, double phi);
6471
+ float ellint_1f(float k, float phi);
6472
+ long double ellint_1l(long double k, long double phi);
6473
+
6474
+ // [sf.cmath.ellint_2], incomplete elliptic integral of the second kind
6475
+ double ellint_2(double k, double phi);
6476
+ float ellint_2f(float k, float phi);
6477
+ long double ellint_2l(long double k, long double phi);
6478
+
6479
+ // [sf.cmath.ellint_3], incomplete elliptic integral of the third kind
6480
+ double ellint_3(double k, double nu, double phi);
6481
+ float ellint_3f(float k, float nu, float phi);
6482
+ long double ellint_3l(long double k, long double nu, long double phi);
6483
+
6484
+ // [sf.cmath.expint], exponential integral
6485
+ double expint(double x);
6486
+ float expintf(float x);
6487
+ long double expintl(long double x);
6488
+
6489
+ // [sf.cmath.hermite], Hermite polynomials
6490
+ double hermite(unsigned n, double x);
6491
+ float hermitef(unsigned n, float x);
6492
+ long double hermitel(unsigned n, long double x);
6493
+
6494
+ // [sf.cmath.laguerre], Laguerre polynomials
6495
+ double laguerre(unsigned n, double x);
6496
+ float laguerref(unsigned n, float x);
6497
+ long double laguerrel(unsigned n, long double x);
6498
+
6499
+ // [sf.cmath.legendre], Legendre polynomials
6500
+ double legendre(unsigned l, double x);
6501
+ float legendref(unsigned l, float x);
6502
+ long double legendrel(unsigned l, long double x);
6503
+
6504
+ // [sf.cmath.riemann_zeta], Riemann zeta function
6505
+ double riemann_zeta(double x);
6506
+ float riemann_zetaf(float x);
6507
+ long double riemann_zetal(long double x);
6508
+
6509
+ // [sf.cmath.sph_bessel], spherical Bessel functions of the first kind
6510
+ double sph_bessel(unsigned n, double x);
6511
+ float sph_besself(unsigned n, float x);
6512
+ long double sph_bessell(unsigned n, long double x);
6513
+
6514
+ // [sf.cmath.sph_legendre], spherical associated Legendre functions
6515
+ double sph_legendre(unsigned l, unsigned m, double theta);
6516
+ float sph_legendref(unsigned l, unsigned m, float theta);
6517
+ long double sph_legendrel(unsigned l, unsigned m, long double theta);
6518
+
6519
+ // [sf.cmath.sph_neumann], spherical Neumann functions;
6520
+ // spherical Bessel functions of the second kind:
6521
+ double sph_neumann(unsigned n, double x);
6522
+ float sph_neumannf(unsigned n, float x);
6523
+ long double sph_neumannl(unsigned n, long double x);
6524
+ }
6525
+ ```
6526
+
6527
+ The contents and meaning of the header `<cmath>` are the same as the C
6528
+ standard library header `<math.h>`, with the addition of a
6529
+ three-dimensional hypotenuse function ([[c.math.hypot3]]) and the
6530
+ mathematical special functions described in [[sf.cmath]].
6531
+
6532
+ [*Note 1*: Several functions have additional overloads in this
6533
+ International Standard, but they have the same behavior as in the C
6534
+ standard library ([[library.c]]). — *end note*]
6535
+
6536
+ For each set of overloaded functions within `<cmath>`, with the
6537
+ exception of `abs`, there shall be additional overloads sufficient to
6538
+ ensure:
6539
+
6540
+ 1. If any argument of arithmetic type corresponding to a `double`
6541
+ parameter has type `long double`, then all arguments of arithmetic
6542
+ type ([[basic.fundamental]]) corresponding to `double` parameters
6543
+ are effectively cast to `long double`.
6544
+ 2. Otherwise, if any argument of arithmetic type corresponding to a
6545
+ `double` parameter has type `double` or an integer type, then all
6546
+ arguments of arithmetic type corresponding to `double` parameters
6547
+ are effectively cast to `double`.
6548
+ 3. Otherwise, all arguments of arithmetic type corresponding to
6549
+ `double` parameters have type `float`.
6550
+
6551
+ [*Note 2*: `abs` is exempted from these rules in order to stay
6552
+ compatible with C. — *end note*]
6553
+
6554
+ ISO C 7.12
6555
+
6556
+ ### Absolute values <a id="c.math.abs">[[c.math.abs]]</a>
6557
+
6558
+ [*Note 1*: The headers `<cstdlib>` ([[cstdlib.syn]]) and `<cmath>` (
6559
+ [[cmath.syn]]) declare the functions described in this
6560
+ subclause. — *end note*]
6561
+
6562
+ ``` cpp
6563
+ int abs(int j);
6564
+ long int abs(long int j);
6565
+ long long int abs(long long int j);
6566
+ float abs(float j);
6567
+ double abs(double j);
6568
+ long double abs(long double j);
6569
+ ```
6570
+
6571
+ *Effects:* The `abs` functions have the semantics specified in the C
6572
+ standard library for the functions `abs`, `labs`, `llabs`, `fabsf`,
6573
+ `fabs`, and `fabsl`.
6574
+
6575
+ *Remarks:* If `abs()` is called with an argument of type `X` for which
6576
+ `is_unsigned_v<X>` is `true` and if `X` cannot be converted to `int` by
6577
+ integral promotion ([[conv.prom]]), the program is ill-formed.
6578
+
6579
+ [*Note 1*: Arguments that can be promoted to `int` are permitted for
6580
+ compatibility with C. — *end note*]
6581
+
6582
+ ISO C 7.12.7.2, 7.22.6.1
6583
+
6584
+ ### Three-dimensional hypotenuse <a id="c.math.hypot3">[[c.math.hypot3]]</a>
6585
+
6586
+ ``` cpp
6587
+ float hypot(float x, float y, float z);
6588
+ double hypot(double x, double y, double z);
6589
+ long double hypot(long double x, long double y, long double z);
6590
+ ```
6591
+
6592
+ *Returns:* $\sqrt{x^2+y^2+z^2}$.
6593
+
6594
+ ### Classification / comparison functions <a id="c.math.fpclass">[[c.math.fpclass]]</a>
6595
+
6596
+ The classification / comparison functions behave the same as the C
6597
+ macros with the corresponding names defined in the C standard library.
6598
+ Each function is overloaded for the three floating-point types.
6599
+
6600
+ ISO C 7.12.3, 7.12.4
6601
+
6602
+ ### Mathematical special functions <a id="sf.cmath">[[sf.cmath]]</a>
6603
+
6604
+ If any argument value to any of the functions specified in this
6605
+ subclause is a NaN (Not a Number), the function shall return a NaN but
6606
+ it shall not report a domain error. Otherwise, the function shall report
6607
+ a domain error for just those argument values for which:
6608
+
6609
+ - the function description’s *Returns:* clause explicitly specifies a
6610
+ domain and those argument values fall outside the specified domain, or
6611
+ - the corresponding mathematical function value has a nonzero imaginary
6612
+ component, or
6613
+ - the corresponding mathematical function is not mathematically
6614
+ defined.[^18]
6615
+
6616
+ Unless otherwise specified, each function is defined for all finite
6617
+ values, for negative infinity, and for positive infinity.
6618
+
6619
+ #### Associated Laguerre polynomials <a id="sf.cmath.assoc_laguerre">[[sf.cmath.assoc_laguerre]]</a>
6620
+
6621
+ ``` cpp
6622
+ double assoc_laguerre(unsigned n, unsigned m, double x);
6623
+ float assoc_laguerref(unsigned n, unsigned m, float x);
6624
+ long double assoc_laguerrel(unsigned n, unsigned m, long double x);
6625
+ ```
6626
+
6627
+ *Effects:* These functions compute the associated Laguerre polynomials
6628
+ of their respective arguments `n`, `m`, and `x`.
6629
+
6630
+ *Returns:* $$%
6631
+ \mathsf{L}_n^m(x) =
6632
+ (-1)^m \frac{\mathsf{d} ^ m}
6633
+ {\mathsf{d}x ^ m} \, \mathsf{L}_{n+m}(x),
6634
+ \quad \mbox{for $x \ge 0$}$$ where n is `n`, m is `m`, and x is
6635
+ `x`.
6636
+
6637
+ *Remarks:* The effect of calling each of these functions is
6638
+ *implementation-defined* if `n >= 128` or if `m >= 128`.
6639
+
6640
+ #### Associated Legendre functions <a id="sf.cmath.assoc_legendre">[[sf.cmath.assoc_legendre]]</a>
6641
+
6642
+ ``` cpp
6643
+ double assoc_legendre(unsigned l, unsigned m, double x);
6644
+ float assoc_legendref(unsigned l, unsigned m, float x);
6645
+ long double assoc_legendrel(unsigned l, unsigned m, long double x);
6646
+ ```
6647
+
6648
+ *Effects:* These functions compute the associated Legendre functions of
6649
+ their respective arguments `l`, `m`, and `x`.
6650
+
6651
+ *Returns:* $$%
6652
+ \mathsf{P}_\ell^m(x) =
6653
+ (1 - x^2) ^ {m/2}
6654
+ \:
6655
+ \frac{ \mathsf{d} ^ m}
6656
+ { \mathsf{d}x ^ m} \, \mathsf{P}_\ell(x),
6657
+ \quad \mbox{for $|x| \le 1$}$$ where l is `l`, m is `m`, and x is
6658
+ `x`.
6659
+
6660
+ *Remarks:* The effect of calling each of these functions is
6661
+ *implementation-defined* if `l >= 128`.
6662
+
6663
+ #### Beta function <a id="sf.cmath.beta">[[sf.cmath.beta]]</a>
6664
+
6665
+ ``` cpp
6666
+ double beta(double x, double y);
6667
+ float betaf(float x, float y);
6668
+ long double betal(long double x, long double y);
6669
+ ```
6670
+
6671
+ *Effects:* These functions compute the beta function of their respective
6672
+ arguments `x` and `y`.
6673
+
6674
+ *Returns:* $$%
6675
+ \mathsf{B}(x, y) =
6676
+ \frac{ \Gamma(x) \, \Gamma(y) }
6677
+ { \Gamma(x+y) },
6678
+ \quad \mbox{for $x > 0$,\, $y > 0$}$$ where x is `x` and y is
6679
+ `y`.
6680
+
6681
+ #### Complete elliptic integral of the first kind <a id="sf.cmath.comp_ellint_1">[[sf.cmath.comp_ellint_1]]</a>
6682
+
6683
+ ``` cpp
6684
+ double comp_ellint_1(double k);
6685
+ float comp_ellint_1f(float k);
6686
+ long double comp_ellint_1l(long double k);
6687
+ ```
6688
+
6689
+ *Effects:* These functions compute the complete elliptic integral of the
6690
+ first kind of their respective arguments `k`.
6691
+
6692
+ *Returns:* $$%
6693
+ \mathsf{K}(k) =
6694
+ \mathsf{F}(k, \pi / 2),
6695
+ \quad \mbox{for $|k| \le 1$}$$ where k is `k`.
6696
+
6697
+ See also [[sf.cmath.ellint_1]].
6698
+
6699
+ #### Complete elliptic integral of the second kind <a id="sf.cmath.comp_ellint_2">[[sf.cmath.comp_ellint_2]]</a>
6700
+
6701
+ ``` cpp
6702
+ double comp_ellint_2(double k);
6703
+ float comp_ellint_2f(float k);
6704
+ long double comp_ellint_2l(long double k);
6705
+ ```
6706
+
6707
+ *Effects:* These functions compute the complete elliptic integral of the
6708
+ second kind of their respective arguments `k`.
6709
+
6710
+ *Returns:* $$%
6711
+ \mathsf{E}(k) =
6712
+ \mathsf{E}(k, \pi / 2),
6713
+ \quad \mbox{for $|k| \le 1$}$$ where k is `k`.
6714
+
6715
+ See also [[sf.cmath.ellint_2]].
6716
+
6717
+ #### Complete elliptic integral of the third kind <a id="sf.cmath.comp_ellint_3">[[sf.cmath.comp_ellint_3]]</a>
6718
+
6719
+ ``` cpp
6720
+ double comp_ellint_3(double k, double nu);
6721
+ float comp_ellint_3f(float k, float nu);
6722
+ long double comp_ellint_3l(long double k, long double nu);
6723
+ ```
6724
+
6725
+ *Effects:* These functions compute the complete elliptic integral of the
6726
+ third kind of their respective arguments `k` and `nu`.
6727
+
6728
+ *Returns:* $$%
6729
+ \mathsf{\Pi}(\nu, k) = \mathsf{\Pi}(\nu, k, \pi / 2),
6730
+ \quad \mbox{for $|k| \le 1$}$$ where k is `k` and $\nu$ is `nu`.
6731
+
6732
+ See also [[sf.cmath.ellint_3]].
6733
+
6734
+ #### Regular modified cylindrical Bessel functions <a id="sf.cmath.cyl_bessel_i">[[sf.cmath.cyl_bessel_i]]</a>
6735
+
6736
+ ``` cpp
6737
+ double cyl_bessel_i(double nu, double x);
6738
+ float cyl_bessel_if(float nu, float x);
6739
+ long double cyl_bessel_il(long double nu, long double x);
6740
+ ```
6741
+
6742
+ *Effects:* These functions compute the regular modified cylindrical
6743
+ Bessel functions of their respective arguments `nu` and `x`.
6744
+
6745
+ *Returns:* $$%
6746
+ \mathsf{I}_\nu(x) =
6747
+ i^{-\nu} \mathsf{J}_\nu(ix)
6748
+ =
6749
+ \sum_{k=0}^\infty \frac{(x/2)^{\nu+2k}}
6750
+ {k! \: \Gamma(\nu+k+1)},
6751
+ \quad \mbox{for $x \ge 0$}$$ where $\nu$ is `nu` and x is `x`.
6752
+
6753
+ *Remarks:* The effect of calling each of these functions is
6754
+ *implementation-defined* if `nu >= 128`.
6755
+
6756
+ See also [[sf.cmath.cyl_bessel_j]].
6757
+
6758
+ #### Cylindrical Bessel functions of the first kind <a id="sf.cmath.cyl_bessel_j">[[sf.cmath.cyl_bessel_j]]</a>
6759
+
6760
+ ``` cpp
6761
+ double cyl_bessel_j(double nu, double x);
6762
+ float cyl_bessel_jf(float nu, float x);
6763
+ long double cyl_bessel_jl(long double nu, long double x);
6764
+ ```
6765
+
6766
+ *Effects:* These functions compute the cylindrical Bessel functions of
6767
+ the first kind of their respective arguments `nu` and `x`.
6768
+
6769
+ *Returns:* $$%
6770
+ \mathsf{J}_\nu(x) =
6771
+ \sum_{k=0}^\infty \frac{(-1)^k (x/2)^{\nu+2k}}
6772
+ {k! \: \Gamma(\nu+k+1)},
6773
+ \quad \mbox{for $x \ge 0$}$$ where $\nu$ is `nu` and x is `x`.
6774
+
6775
+ *Remarks:* The effect of calling each of these functions is
6776
+ *implementation-defined* if `nu >= 128`.
6777
+
6778
+ #### Irregular modified cylindrical Bessel functions <a id="sf.cmath.cyl_bessel_k">[[sf.cmath.cyl_bessel_k]]</a>
6779
+
6780
+ ``` cpp
6781
+ double cyl_bessel_k(double nu, double x);
6782
+ float cyl_bessel_kf(float nu, float x);
6783
+ long double cyl_bessel_kl(long double nu, long double x);
6784
+ ```
6785
+
6786
+ *Effects:* These functions compute the irregular modified cylindrical
6787
+ Bessel functions of their respective arguments `nu` and `x`.
6788
+
6789
+ *Returns:* $$%
6790
+ \mathsf{K}_\nu(x) =
6791
+ (\pi/2)i^{\nu+1} ( \mathsf{J}_\nu(ix)
6792
+ + i \mathsf{N}_\nu(ix)
6793
+ )
6794
+ =
6795
+ \left\{
6796
+ \begin{array}{cl}
6797
+ \displaystyle
6798
+ \frac{\pi}{2}
6799
+ \frac{\mathsf{I}_{-\nu}(x) - \mathsf{I}_{\nu}(x)}
6800
+ {\sin \nu\pi },
6801
+ & \mbox{for $x \ge 0$ and non-integral $\nu$}
6802
+ \\
6803
+ \\
6804
+ \displaystyle
6805
+ \frac{\pi}{2}
6806
+ \lim_{\mu \rightarrow \nu} \frac{\mathsf{I}_{-\mu}(x) - \mathsf{I}_{\mu}(x)}
6807
+ {\sin \mu\pi },
6808
+ & \mbox{for $x \ge 0$ and integral $\nu$}
6809
+ \end{array}
6810
+ \right.$$ where $\nu$ is `nu` and x is `x`.
6811
+
6812
+ *Remarks:* The effect of calling each of these functions is
6813
+ *implementation-defined* if `nu >= 128`.
6814
+
6815
+ See also [[sf.cmath.cyl_bessel_i]], [[sf.cmath.cyl_bessel_j]],
6816
+ [[sf.cmath.cyl_neumann]].
6817
+
6818
+ #### Cylindrical Neumann functions <a id="sf.cmath.cyl_neumann">[[sf.cmath.cyl_neumann]]</a>
6819
+
6820
+ ``` cpp
6821
+ double cyl_neumann(double nu, double x);
6822
+ float cyl_neumannf(float nu, float x);
6823
+ long double cyl_neumannl(long double nu, long double x);
6824
+ ```
6825
+
6826
+ *Effects:* These functions compute the cylindrical Neumann functions,
6827
+ also known as the cylindrical Bessel functions of the second kind, of
6828
+ their respective arguments `nu` and `x`.
6829
+
6830
+ *Returns:* $$%
6831
+ \mathsf{N}_\nu(x) =
6832
+ \left\{
6833
+ \begin{array}{cl}
6834
+ \displaystyle
6835
+ \frac{\mathsf{J}_\nu(x) \cos \nu\pi - \mathsf{J}_{-\nu}(x)}
6836
+ {\sin \nu\pi },
6837
+ & \mbox{for $x \ge 0$ and non-integral $\nu$}
6838
+ \\
6839
+ \\
6840
+ \displaystyle
6841
+ \lim_{\mu \rightarrow \nu} \frac{\mathsf{J}_\mu(x) \cos \mu\pi - \mathsf{J}_{-\mu}(x)}
6842
+ {\sin \mu\pi },
6843
+ & \mbox{for $x \ge 0$ and integral $\nu$}
6844
+ \end{array}
6845
+ \right.$$ where $\nu$ is `nu` and x is `x`.
6846
+
6847
+ *Remarks:* The effect of calling each of these functions is
6848
+ *implementation-defined* if `nu >= 128`.
6849
+
6850
+ See also [[sf.cmath.cyl_bessel_j]].
6851
+
6852
+ #### Incomplete elliptic integral of the first kind <a id="sf.cmath.ellint_1">[[sf.cmath.ellint_1]]</a>
6853
+
6854
+ ``` cpp
6855
+ double ellint_1(double k, double phi);
6856
+ float ellint_1f(float k, float phi);
6857
+ long double ellint_1l(long double k, long double phi);
6858
+ ```
6859
+
6860
+ *Effects:* These functions compute the incomplete elliptic integral of
6861
+ the first kind of their respective arguments `k` and `phi` (`phi`
6862
+ measured in radians).
6863
+
6864
+ *Returns:* $$%
6865
+ \mathsf{F}(k, \phi) =
6866
+ \int_0^\phi \! \frac{\mathsf{d}\theta}
6867
+ {\sqrt{1 - k^2 \sin^2 \theta}},
6868
+ \quad \mbox{for $|k| \le 1$}$$ where k is `k` and φ is `phi`.
6869
+
6870
+ #### Incomplete elliptic integral of the second kind <a id="sf.cmath.ellint_2">[[sf.cmath.ellint_2]]</a>
6871
+
6872
+ ``` cpp
6873
+ double ellint_2(double k, double phi);
6874
+ float ellint_2f(float k, float phi);
6875
+ long double ellint_2l(long double k, long double phi);
6876
+ ```
6877
+
6878
+ *Effects:* These functions compute the incomplete elliptic integral of
6879
+ the second kind of their respective arguments `k` and `phi` (`phi`
6880
+ measured in radians).
6881
+
6882
+ *Returns:* $$%
6883
+ \mathsf{E}(k, \phi) =
6884
+ \int_0^\phi \! \sqrt{1 - k^2 \sin^2 \theta} \, \mathsf{d}\theta,
6885
+ \quad \mbox{for $|k| \le 1$}$$ where k is `k` and φ is `phi`.
6886
+
6887
+ #### Incomplete elliptic integral of the third kind <a id="sf.cmath.ellint_3">[[sf.cmath.ellint_3]]</a>
6888
+
6889
+ ``` cpp
6890
+ double ellint_3(double k, double nu, double phi);
6891
+ float ellint_3f(float k, float nu, float phi);
6892
+ long double ellint_3l(long double k, long double nu, long double phi);
6893
+ ```
6894
+
6895
+ *Effects:* These functions compute the incomplete elliptic integral of
6896
+ the third kind of their respective arguments `k`, `nu`, and `phi` (`phi`
6897
+ measured in radians).
6898
+
6899
+ *Returns:* $$%
6900
+ \mathsf{\Pi}(\nu, k, \phi) =
6901
+ \int_0^\phi \! \frac{ \mathsf{d}\theta }
6902
+ { (1 - \nu \, \sin^2 \theta) \sqrt{1 - k^2 \sin^2 \theta} },
6903
+ \quad \mbox{for $|k| \le 1$}$$ where $\nu$ is `nu`, k is `k`, and
6904
+ φ is `phi`.
6905
+
6906
+ #### Exponential integral <a id="sf.cmath.expint">[[sf.cmath.expint]]</a>
6907
+
6908
+ ``` cpp
6909
+ double expint(double x);
6910
+ float expintf(float x);
6911
+ long double expintl(long double x);
6912
+ ```
6913
+
6914
+ *Effects:* These functions compute the exponential integral of their
6915
+ respective arguments `x`.
6916
+
6917
+ *Returns:* $$%
6918
+ \mathsf{Ei}(x) =
6919
+ - \int_{-x}^\infty \frac{e^{-t}}
6920
+ {t } \, \mathsf{d}t
6921
+ \;$$ where x is `x`.
6922
+
6923
+ #### Hermite polynomials <a id="sf.cmath.hermite">[[sf.cmath.hermite]]</a>
6924
+
6925
+ ``` cpp
6926
+ double hermite(unsigned n, double x);
6927
+ float hermitef(unsigned n, float x);
6928
+ long double hermitel(unsigned n, long double x);
6929
+ ```
6930
+
6931
+ *Effects:* These functions compute the Hermite polynomials of their
6932
+ respective arguments `n` and `x`.
6933
+
6934
+ *Returns:* $$%
6935
+ \mathsf{H}_n(x) =
6936
+ (-1)^n e^{x^2} \frac{ \mathsf{d} ^n}
6937
+ { \mathsf{d}x^n} \, e^{-x^2}
6938
+ \;$$ where n is `n` and x is `x`.
6939
+
6940
+ *Remarks:* The effect of calling each of these functions is
6941
+ *implementation-defined* if `n >= 128`.
6942
+
6943
+ #### Laguerre polynomials <a id="sf.cmath.laguerre">[[sf.cmath.laguerre]]</a>
6944
+
6945
+ ``` cpp
6946
+ double laguerre(unsigned n, double x);
6947
+ float laguerref(unsigned n, float x);
6948
+ long double laguerrel(unsigned n, long double x);
6949
+ ```
6950
+
6951
+ *Effects:* These functions compute the Laguerre polynomials of their
6952
+ respective arguments `n` and `x`.
6953
+
6954
+ *Returns:* $$%
6955
+ \mathsf{L}_n(x) =
6956
+ \frac{e^x}{n!} \frac{ \mathsf{d} ^ n}
6957
+ { \mathsf{d}x ^ n} \, (x^n e^{-x}),
6958
+ \quad \mbox{for $x \ge 0$}$$ where n is `n` and x is `x`.
6959
+
6960
+ *Remarks:* The effect of calling each of these functions is
6961
+ *implementation-defined* if `n >= 128`.
6962
+
6963
+ #### Legendre polynomials <a id="sf.cmath.legendre">[[sf.cmath.legendre]]</a>
6964
+
6965
+ ``` cpp
6966
+ double legendre(unsigned l, double x);
6967
+ float legendref(unsigned l, float x);
6968
+ long double legendrel(unsigned l, long double x);
6969
+ ```
6970
+
6971
+ *Effects:* These functions compute the Legendre polynomials of their
6972
+ respective arguments `l` and `x`.
6973
+
6974
+ *Returns:* $$%
6975
+ \mathsf{P}_\ell(x) =
6976
+ \frac{1}
6977
+ {2^\ell \, \ell!}
6978
+ \frac{ \mathsf{d} ^ \ell}
6979
+ { \mathsf{d}x ^ \ell} \, (x^2 - 1) ^ \ell,
6980
+ \quad \mbox{for $|x| \le 1$}$$ where l is `l` and x is `x`.
6981
+
6982
+ *Remarks:* The effect of calling each of these functions is
6983
+ *implementation-defined* if `l >= 128`.
6984
+
6985
+ #### Riemann zeta function <a id="sf.cmath.riemann_zeta">[[sf.cmath.riemann_zeta]]</a>
6986
+
6987
+ ``` cpp
6988
+ double riemann_zeta(double x);
6989
+ float riemann_zetaf(float x);
6990
+ long double riemann_zetal(long double x);
6991
+ ```
6992
+
6993
+ *Effects:* These functions compute the Riemann zeta function of their
6994
+ respective arguments `x`.
6995
+
6996
+ *Returns:* $$%
6997
+ \mathsf{\zeta}(x) =
6998
+ \left\{
6999
+ \begin{array}{cl}
7000
+ \displaystyle
7001
+ \sum_{k=1}^\infty k^{-x},
7002
+ & \mbox{for $x > 1$}
7003
+ \\
7004
+ \\
7005
+ \displaystyle
7006
+ \frac{1}
7007
+ {1 - 2^{1-x}}
7008
+ \sum_{k=1}^\infty (-1)^{k-1} k^{-x},
7009
+ & \mbox{for $0 \le x \le 1$}
7010
+ \\
7011
+ \\
7012
+ \displaystyle
7013
+ 2^x \pi^{x-1} \sin(\frac{\pi x}{2}) \, \Gamma(1-x) \, \zeta(1-x),
7014
+ & \mbox{for $x < 0$}
7015
+ \end{array}
7016
+ \right.
7017
+ \;$$ where x is `x`.
7018
+
7019
+ #### Spherical Bessel functions of the first kind <a id="sf.cmath.sph_bessel">[[sf.cmath.sph_bessel]]</a>
7020
+
7021
+ ``` cpp
7022
+ double sph_bessel(unsigned n, double x);
7023
+ float sph_besself(unsigned n, float x);
7024
+ long double sph_bessell(unsigned n, long double x);
7025
+ ```
7026
+
7027
+ *Effects:* These functions compute the spherical Bessel functions of the
7028
+ first kind of their respective arguments `n` and `x`.
7029
+
7030
+ *Returns:* $$%
7031
+ \mathsf{j}_n(x) =
7032
+ (\pi/2x)^{1\!/\!2} \mathsf{J}_{n + 1\!/\!2}(x),
7033
+ \quad \mbox{for $x \ge 0$}$$ where n is `n` and x is `x`.
7034
+
7035
+ *Remarks:* The effect of calling each of these functions is
7036
+ *implementation-defined* if `n >= 128`.
7037
+
7038
+ See also [[sf.cmath.cyl_bessel_j]].
7039
+
7040
+ #### Spherical associated Legendre functions <a id="sf.cmath.sph_legendre">[[sf.cmath.sph_legendre]]</a>
7041
+
7042
+ ``` cpp
7043
+ double sph_legendre(unsigned l, unsigned m, double theta);
7044
+ float sph_legendref(unsigned l, unsigned m, float theta);
7045
+ long double sph_legendrel(unsigned l, unsigned m, long double theta);
7046
+ ```
7047
+
7048
+ *Effects:* These functions compute the spherical associated Legendre
7049
+ functions of their respective arguments `l`, `m`, and `theta` (`theta`
7050
+ measured in radians).
7051
+
7052
+ *Returns:* $$%
7053
+ \mathsf{Y}_\ell^m(\theta, 0)
7054
+ \;$$ where $$%
7055
+ \mathsf{Y}_\ell^m(\theta, \phi) =
7056
+ (-1)^m \left[ \frac{(2 \ell + 1)}
7057
+ {4 \pi}
7058
+ \frac{(\ell - m)!}
7059
+ {(\ell + m)!}
7060
+ \right]^{1/2}
7061
+ \mathsf{P}_\ell^m
7062
+ ( \cos\theta ) e ^ {i m \phi},
7063
+ \quad \mbox{for $|m| \le \ell$}$$ and l is `l`, m is `m`, and θ
7064
+ is `theta`.
7065
+
7066
+ *Remarks:* The effect of calling each of these functions is
7067
+ *implementation-defined* if `l >= 128`.
7068
+
7069
+ See also [[sf.cmath.assoc_legendre]].
7070
+
7071
+ #### Spherical Neumann functions <a id="sf.cmath.sph_neumann">[[sf.cmath.sph_neumann]]</a>
7072
+
7073
+ ``` cpp
7074
+ double sph_neumann(unsigned n, double x);
7075
+ float sph_neumannf(unsigned n, float x);
7076
+ long double sph_neumannl(unsigned n, long double x);
7077
+ ```
7078
+
7079
+ *Effects:* These functions compute the spherical Neumann functions, also
7080
+ known as the spherical Bessel functions of the second kind, of their
7081
+ respective arguments `n` and `x`.
7082
+
7083
+ *Returns:* $$%
7084
+ \mathsf{n}_n(x) =
7085
+ (\pi/2x)^{1\!/\!2} \mathsf{N}_{n + 1\!/\!2}(x),
7086
+ \quad \mbox{for $x \ge 0$}$$ where n is `n` and x is `x`.
7087
+
7088
+ *Remarks:* The effect of calling each of these functions is
7089
+ *implementation-defined* if `n >= 128`.
7090
+
7091
+ See also [[sf.cmath.cyl_neumann]].
7092
 
7093
  <!-- Link reference definitions -->
7094
  [accumulate]: #accumulate
7095
  [adjacent.difference]: #adjacent.difference
7096
  [algorithms]: algorithms.md#algorithms
7097
  [bad.alloc]: language.md#bad.alloc
7098
  [basic.fundamental]: basic.md#basic.fundamental
7099
  [basic.stc.thread]: basic.md#basic.stc.thread
7100
  [basic.types]: basic.md#basic.types
7101
  [c.math]: #c.math
7102
+ [c.math.abs]: #c.math.abs
7103
+ [c.math.fpclass]: #c.math.fpclass
7104
+ [c.math.hypot3]: #c.math.hypot3
7105
+ [c.math.rand]: #c.math.rand
7106
  [cfenv]: #cfenv
7107
  [cfenv.syn]: #cfenv.syn
7108
  [class.gslice]: #class.gslice
7109
  [class.gslice.overview]: #class.gslice.overview
7110
  [class.slice]: #class.slice
7111
  [class.slice.overview]: #class.slice.overview
7112
+ [cmath.syn]: #cmath.syn
7113
  [cmplx.over]: #cmplx.over
7114
  [complex]: #complex
7115
  [complex.literals]: #complex.literals
7116
  [complex.member.ops]: #complex.member.ops
7117
  [complex.members]: #complex.members
 
7120
  [complex.special]: #complex.special
7121
  [complex.syn]: #complex.syn
7122
  [complex.transcendentals]: #complex.transcendentals
7123
  [complex.value.ops]: #complex.value.ops
7124
  [cons.slice]: #cons.slice
7125
+ [conv.prom]: conv.md#conv.prom
7126
+ [cpp.pragma]: cpp.md#cpp.pragma
7127
+ [cstdlib.syn]: language.md#cstdlib.syn
7128
+ [dcl.array]: dcl.md#dcl.array
7129
  [dcl.init]: dcl.md#dcl.init
7130
+ [exclusive.scan]: #exclusive.scan
7131
  [function.objects]: utilities.md#function.objects
7132
  [gslice.access]: #gslice.access
7133
  [gslice.array.assign]: #gslice.array.assign
7134
  [gslice.array.comp.assign]: #gslice.array.comp.assign
7135
  [gslice.array.fill]: #gslice.array.fill
7136
  [gslice.cons]: #gslice.cons
7137
+ [implimits]: limits.md#implimits
7138
+ [inclusive.scan]: #inclusive.scan
7139
  [indirect.array.assign]: #indirect.array.assign
7140
  [indirect.array.comp.assign]: #indirect.array.comp.assign
7141
  [indirect.array.fill]: #indirect.array.fill
7142
  [inner.product]: #inner.product
7143
+ [input.iterators]: iterators.md#input.iterators
7144
  [input.output]: input.md#input.output
7145
  [iostate.flags]: input.md#iostate.flags
7146
  [istream.formatted]: input.md#istream.formatted
7147
+ [iterator.requirements.general]: iterators.md#iterator.requirements.general
7148
+ [library.c]: library.md#library.c
7149
  [mask.array.assign]: #mask.array.assign
7150
  [mask.array.comp.assign]: #mask.array.comp.assign
7151
  [mask.array.fill]: #mask.array.fill
 
7152
  [numarray]: #numarray
7153
  [numeric.iota]: #numeric.iota
7154
  [numeric.ops]: #numeric.ops
7155
+ [numeric.ops.gcd]: #numeric.ops.gcd
7156
+ [numeric.ops.lcm]: #numeric.ops.lcm
7157
  [numeric.ops.overview]: #numeric.ops.overview
7158
  [numeric.requirements]: #numeric.requirements
7159
  [numerics]: #numerics
7160
+ [numerics.defns]: #numerics.defns
7161
  [numerics.general]: #numerics.general
7162
+ [output.iterators]: iterators.md#output.iterators
7163
  [partial.sum]: #partial.sum
7164
  [rand]: #rand
7165
  [rand.adapt]: #rand.adapt
7166
  [rand.adapt.disc]: #rand.adapt.disc
7167
  [rand.adapt.general]: #rand.adapt.general
 
7210
  [rand.synopsis]: #rand.synopsis
7211
  [rand.util]: #rand.util
7212
  [rand.util.canonical]: #rand.util.canonical
7213
  [rand.util.seedseq]: #rand.util.seedseq
7214
  [random.access.iterators]: iterators.md#random.access.iterators
7215
+ [reduce]: #reduce
7216
  [res.on.data.races]: library.md#res.on.data.races
7217
+ [sf.cmath]: #sf.cmath
7218
+ [sf.cmath.assoc_laguerre]: #sf.cmath.assoc_laguerre
7219
+ [sf.cmath.assoc_legendre]: #sf.cmath.assoc_legendre
7220
+ [sf.cmath.beta]: #sf.cmath.beta
7221
+ [sf.cmath.comp_ellint_1]: #sf.cmath.comp_ellint_1
7222
+ [sf.cmath.comp_ellint_2]: #sf.cmath.comp_ellint_2
7223
+ [sf.cmath.comp_ellint_3]: #sf.cmath.comp_ellint_3
7224
+ [sf.cmath.cyl_bessel_i]: #sf.cmath.cyl_bessel_i
7225
+ [sf.cmath.cyl_bessel_j]: #sf.cmath.cyl_bessel_j
7226
+ [sf.cmath.cyl_bessel_k]: #sf.cmath.cyl_bessel_k
7227
+ [sf.cmath.cyl_neumann]: #sf.cmath.cyl_neumann
7228
+ [sf.cmath.ellint_1]: #sf.cmath.ellint_1
7229
+ [sf.cmath.ellint_2]: #sf.cmath.ellint_2
7230
+ [sf.cmath.ellint_3]: #sf.cmath.ellint_3
7231
+ [sf.cmath.expint]: #sf.cmath.expint
7232
+ [sf.cmath.hermite]: #sf.cmath.hermite
7233
+ [sf.cmath.laguerre]: #sf.cmath.laguerre
7234
+ [sf.cmath.legendre]: #sf.cmath.legendre
7235
+ [sf.cmath.riemann_zeta]: #sf.cmath.riemann_zeta
7236
+ [sf.cmath.sph_bessel]: #sf.cmath.sph_bessel
7237
+ [sf.cmath.sph_legendre]: #sf.cmath.sph_legendre
7238
+ [sf.cmath.sph_neumann]: #sf.cmath.sph_neumann
7239
  [slice.access]: #slice.access
7240
  [slice.arr.assign]: #slice.arr.assign
7241
  [slice.arr.comp.assign]: #slice.arr.comp.assign
7242
  [slice.arr.fill]: #slice.arr.fill
7243
  [strings]: strings.md#strings
7244
  [tab:RandomDistribution]: #tab:RandomDistribution
7245
  [tab:RandomEngine]: #tab:RandomEngine
7246
  [tab:SeedSequence]: #tab:SeedSequence
7247
+ [tab:UniformRandomBitGenerator]: #tab:UniformRandomBitGenerator
7248
+ [tab:copyassignable]: #tab:copyassignable
7249
+ [tab:copyconstructible]: #tab:copyconstructible
7250
+ [tab:equalitycomparable]: #tab:equalitycomparable
7251
  [tab:iterator.input.requirements]: iterators.md#tab:iterator.input.requirements
7252
+ [tab:moveassignable]: #tab:moveassignable
7253
+ [tab:moveconstructible]: #tab:moveconstructible
 
 
7254
  [tab:numerics.lib.summary]: #tab:numerics.lib.summary
7255
  [template.gslice.array]: #template.gslice.array
7256
  [template.gslice.array.overview]: #template.gslice.array.overview
7257
  [template.indirect.array]: #template.indirect.array
7258
  [template.indirect.array.overview]: #template.indirect.array.overview
 
7261
  [template.slice.array]: #template.slice.array
7262
  [template.slice.array.overview]: #template.slice.array.overview
7263
  [template.valarray]: #template.valarray
7264
  [template.valarray.overview]: #template.valarray.overview
7265
  [thread.thread.class]: thread.md#thread.thread.class
7266
+ [transform.exclusive.scan]: #transform.exclusive.scan
7267
+ [transform.inclusive.scan]: #transform.inclusive.scan
7268
+ [transform.reduce]: #transform.reduce
7269
  [valarray.access]: #valarray.access
7270
  [valarray.assign]: #valarray.assign
7271
  [valarray.binary]: #valarray.binary
7272
  [valarray.cassign]: #valarray.cassign
7273
  [valarray.comparison]: #valarray.comparison
 
7303
  [^6]: The distribution corresponding to this probability density
7304
  function is also known (with a possible change of variable) as the
7305
  Gumbel Type I, the log-Weibull, or the Fisher-Tippett Type I
7306
  distribution.
7307
 
7308
+ [^7]: Annex  [[implimits]] recommends a minimum number of recursively
7309
  nested template instantiations. This requirement thus indirectly
7310
  suggests a minimum allowable complexity for valarray expressions.
7311
 
7312
  [^8]: The intent is to specify an array template that has the minimum
7313
  functionality necessary to address aliasing ambiguities and the
7314
  proliferation of temporaries. Thus, the `valarray` template is
7315
  neither a matrix class nor a field class. However, it is a very
7316
  useful building block for designing such classes.
7317
 
7318
+ [^9]: This default constructor is essential, since arrays of `valarray`
 
 
 
7319
  may be useful. After initialization, the length of an empty array
7320
  can be increased with the `resize` member function.
7321
 
7322
+ [^10]: This constructor is the preferred method for converting a C array
7323
  to a `valarray` object.
7324
 
7325
+ [^11]: This copy constructor creates a distinct array rather than an
7326
  alias. Implementations in which arrays share storage are permitted,
7327
  but they shall implement a copy-on-reference mechanism to ensure
7328
  that arrays are conceptually distinct.
7329
 
7330
+ [^12]: BLAS stands for *Basic Linear Algebra Subprograms.* C++programs
 
 
 
 
7331
  may instantiate this class. See, for example, Dongarra, Du Croz,
7332
  Duff, and Hammerling: *A set of Level 3 Basic Linear Algebra
7333
  Subprograms*; Technical Report MCS-P1-0888, Argonne National
7334
  Laboratory (USA), Mathematics and Computer Science Division, August,
7335
  1988.
7336
 
7337
+ [^13]: The use of fully closed ranges is intentional.
7338
+
7339
+ [^14]: `accumulate` is similar to the APL reduction operator and Common
7340
  Lisp reduce function, but it avoids the difficulty of defining the
7341
  result of reduction on an empty sequence by always requiring an
7342
  initial value.
7343
 
7344
+ [^15]: The use of fully closed ranges is intentional.
7345
 
7346
+ [^16]: The use of fully closed ranges is intentional.
7347
 
7348
+ [^17]: The use of fully closed ranges is intentional.
7349
 
7350
+ [^18]: A mathematical function is mathematically defined for a given set
7351
+ of argument values (a) if it is explicitly defined for that set of
7352
+ argument values, or (b) if its limiting value exists and does not
7353
+ depend on the direction of approach.