From Jason Turner

[rand.req]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmppsk2vzj0/{from.md → to.md} +134 -44
tmp/tmppsk2vzj0/{from.md → to.md} RENAMED
@@ -3,18 +3,39 @@
3
  #### General requirements <a id="rand.req.genl">[[rand.req.genl]]</a>
4
 
5
  Throughout this subclause [[rand]], the effect of instantiating a
6
  template:
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  Throughout this subclause [[rand]], phrases of the form “`x` is an
9
  iterator of a specific kind” shall be interpreted as equivalent to the
10
- more formal requirement that “`x` is a value of a type satisfying the
11
  requirements of the specified iterator type”.
12
 
13
  Throughout this subclause [[rand]], any constructor that can be called
14
- with a single argument and that satisfies a requirement specified in
15
- this subclause shall be declared `explicit`.
16
 
17
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
18
 
19
  A *seed sequence* is an object that consumes a sequence of
20
  integer-valued data and produces a requested number of unsigned integer
@@ -23,61 +44,105 @@ values i, 0 ≤ i < 2³², based on the consumed data.
23
  [*Note 1*: Such an object provides a mechanism to avoid replication of
24
  streams of random variates. This can be useful, for example, in
25
  applications requiring large numbers of random number
26
  engines. — *end note*]
27
 
28
- A class `S` satisfies the requirements of a seed sequence if the
29
- expressions shown in Table  [[tab:SeedSequence]] are valid and have the
30
- indicated semantics, and if `S` also satisfies all other requirements of
31
- this section [[rand.req.seedseq]]. In that Table and throughout this
32
- section:
 
 
 
 
 
 
 
 
 
33
 
34
  #### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
35
 
36
  A *uniform random bit generator* `g` of type `G` is a function object
37
  returning unsigned integer values such that each value in the range of
38
  possible results has (ideally) equal probability of being returned.
39
 
40
  [*Note 1*: The degree to which `g`’s results approximate the ideal is
41
  often determined statistically. — *end note*]
42
 
43
- A class `G` satisfies the requirements of a *uniform random bit
44
- generator* if the expressions shown in Table 
45
- [[tab:UniformRandomBitGenerator]] are valid and have the indicated
46
- semantics, and if `G` also satisfies all other requirements of this
47
- section [[rand.req.urng]]. In that Table and throughout this section:
 
 
 
 
 
48
 
49
- The following relation shall hold: `G::min() < G::max()`.
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
52
 
53
  A *random number engine* (commonly shortened to *engine*) `e` of type
54
  `E` is a uniform random bit generator that additionally meets the
55
  requirements (e.g., for seeding and for input/output) specified in this
56
- section.
57
 
58
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
59
  construction, `e` has an initial state e₀. An engine’s state may be
60
  established via a constructor, a `seed` function, assignment, or a
61
  suitable `operator>>`.
62
 
63
  `E`’s specification shall define:
64
 
65
- A class `E` that satisfies the requirements of a uniform random bit
66
- generator ([[rand.req.urng]]) also satisfies the requirements of a
67
- *random number engine* if the expressions shown in Table 
68
- [[tab:RandomEngine]] are valid and have the indicated semantics, and if
69
- `E` also satisfies all other requirements of this section
70
- [[rand.req.eng]]. In that Table and throughout this section:
71
-
72
- where `charT` and `traits` are constrained according to Clause 
73
- [[strings]] and Clause  [[input.output]].
74
-
75
- `E` shall meet the requirements of `CopyConstructible` (Table 
76
- [[tab:copyconstructible]]) and `CopyAssignable` (Table 
77
- [[tab:copyassignable]]) types. These operations shall each be of
78
- complexity no worse than 𝑂(\mbox{size of state}).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
81
 
82
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
83
  of type `A` is a random number engine that takes values produced by some
@@ -132,11 +197,20 @@ void seed(result_type s);
132
  template<class Sseq> void seed(Sseq& q);
133
  ```
134
 
135
  *Effects:* With `b` as the base engine, invokes `b.seed(q)`.
136
 
137
- `A` shall also satisfy the following additional requirements:
 
 
 
 
 
 
 
 
 
138
 
139
  #### Random number distribution requirements <a id="rand.req.dist">[[rand.req.dist]]</a>
140
 
141
  A *random number distribution* (commonly shortened to *distribution*)
142
  `d` of type `D` is a function object returning values that are
@@ -151,22 +225,38 @@ distribution*. Such distribution parameters are identified in this
151
  context by writing, for example, p(z | a,b) or P(zᵢ | a,b), to name
152
  specific parameters, or by writing, for example, p(z |{`p`}) or
153
  P(zᵢ |{`p`}), to denote a distribution’s parameters `p` taken as a
154
  whole.
155
 
156
- A class `D` satisfies the requirements of a *random number distribution*
157
- if the expressions shown in Table  [[tab:RandomDistribution]] are valid
158
- and have the indicated semantics, and if `D` and its associated types
159
- also satisfy all other requirements of this section [[rand.req.dist]].
160
- In that Table and throughout this section,
161
 
162
- where `charT` and `traits` are constrained according to Clauses 
163
- [[strings]] and [[input.output]].
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
- `D` shall satisfy the requirements of `CopyConstructible` (Table 
166
- [[tab:copyconstructible]]) and `CopyAssignable` (Table 
167
- [[tab:copyassignable]]) types.
 
 
 
168
 
169
  The sequence of numbers produced by repeated invocations of `d(g)` shall
170
  be independent of any invocation of `os << d` or of any `const` member
171
  function of `D` between any of the invocations `d(g)`.
172
 
@@ -179,14 +269,14 @@ produce the same sequence of numbers as would repeated invocations of
179
  It is unspecified whether `D::param_type` is declared as a (nested)
180
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
181
  `D::param_type` are in the form of `typedef`s for convenience of
182
  exposition only.
183
 
184
- `P` shall satisfy the requirements of `CopyConstructible` (Table 
185
- [[tab:copyconstructible]]), `CopyAssignable` (Table 
186
- [[tab:copyassignable]]), and `EqualityComparable` (Table 
187
- [[tab:equalitycomparable]]) types.
188
 
189
  For each of the constructors of `D` taking arguments corresponding to
190
  parameters of the distribution, `P` shall have a corresponding
191
  constructor subject to the same requirements and taking arguments
192
  identical in number, type, and default values. Moreover, for each of the
 
3
  #### General requirements <a id="rand.req.genl">[[rand.req.genl]]</a>
4
 
5
  Throughout this subclause [[rand]], the effect of instantiating a
6
  template:
7
 
8
+ - that has a template type parameter named `Sseq` is undefined unless
9
+ the corresponding template argument is cv-unqualified and meets the
10
+ requirements of seed sequence [[rand.req.seedseq]].
11
+ - that has a template type parameter named `URBG` is undefined unless
12
+ the corresponding template argument is cv-unqualified and meets the
13
+ requirements of uniform random bit generator [[rand.req.urng]].
14
+ - that has a template type parameter named `Engine` is undefined unless
15
+ the corresponding template argument is cv-unqualified and meets the
16
+ requirements of random number engine [[rand.req.eng]].
17
+ - that has a template type parameter named `RealType` is undefined
18
+ unless the corresponding template argument is cv-unqualified and is
19
+ one of `float`, `double`, or `long double`.
20
+ - that has a template type parameter named `IntType` is undefined unless
21
+ the corresponding template argument is cv-unqualified and is one of
22
+ `short`, `int`, `long`, `long long`, `unsigned short`, `unsigned int`,
23
+ `unsigned long`, or `unsigned long long`.
24
+ - that has a template type parameter named `UIntType` is undefined
25
+ unless the corresponding template argument is cv-unqualified and is
26
+ one of `unsigned short`, `unsigned int`, `unsigned long`, or
27
+ `unsigned long long`.
28
+
29
  Throughout this subclause [[rand]], phrases of the form “`x` is an
30
  iterator of a specific kind” shall be interpreted as equivalent to the
31
+ more formal requirement that “`x` is a value of a type meeting the
32
  requirements of the specified iterator type”.
33
 
34
  Throughout this subclause [[rand]], any constructor that can be called
35
+ with a single argument and that meets a requirement specified in this
36
+ subclause shall be declared `explicit`.
37
 
38
  #### Seed sequence requirements <a id="rand.req.seedseq">[[rand.req.seedseq]]</a>
39
 
40
  A *seed sequence* is an object that consumes a sequence of
41
  integer-valued data and produces a requested number of unsigned integer
 
44
  [*Note 1*: Such an object provides a mechanism to avoid replication of
45
  streams of random variates. This can be useful, for example, in
46
  applications requiring large numbers of random number
47
  engines. — *end note*]
48
 
49
+ A class `S` meets the requirements of a seed sequence if the expressions
50
+ shown in [[rand.req.seedseq]] are valid and have the indicated
51
+ semantics, and if `S` also meets all other requirements of this
52
+ subclause [[rand.req.seedseq]]. In that Table and throughout this
53
+ subclause:
54
+
55
+ - `T` is the type named by `S`’s associated `result_type`;
56
+ - `q` is a value of `S` and `r` is a possibly const value of `S`;
57
+ - `ib` and `ie` are input iterators with an unsigned integer
58
+ `value_type` of at least 32 bits;
59
+ - `rb` and `re` are mutable random access iterators with an unsigned
60
+ integer `value_type` of at least 32 bits;
61
+ - `ob` is an output iterator; and
62
+ - `il` is a value of `initializer_list<T>`.
63
 
64
  #### Uniform random bit generator requirements <a id="rand.req.urng">[[rand.req.urng]]</a>
65
 
66
  A *uniform random bit generator* `g` of type `G` is a function object
67
  returning unsigned integer values such that each value in the range of
68
  possible results has (ideally) equal probability of being returned.
69
 
70
  [*Note 1*: The degree to which `g`’s results approximate the ideal is
71
  often determined statistically. — *end note*]
72
 
73
+ ``` cpp
74
+ template<class G>
75
+ concept uniform_random_bit_generator =
76
+ invocable<G&> && unsigned_integral<invoke_result_t<G&>> &&
77
+ requires {
78
+ { G::min() } -> same_as<invoke_result_t<G&>>;
79
+ { G::max() } -> same_as<invoke_result_t<G&>>;
80
+ requires bool_constant<(G::min() < G::max())>::value;
81
+ };
82
+ ```
83
 
84
+ Let `g` be an object of type `G`. `G` models
85
+ `uniform_random_bit_generator` only if
86
+
87
+ - `G::min() <= g()`,
88
+ - `g() <= G::max()`, and
89
+ - `g()` has amortized constant complexity.
90
+
91
+ A class `G` meets the *uniform random bit generator* requirements if `G`
92
+ models `uniform_random_bit_generator`, `invoke_result_t<G&>` is an
93
+ unsigned integer type [[basic.fundamental]], and `G` provides a nested
94
+ *typedef-name* `result_type` that denotes the same type as
95
+ `invoke_result_t<G&>`.
96
 
97
  #### Random number engine requirements <a id="rand.req.eng">[[rand.req.eng]]</a>
98
 
99
  A *random number engine* (commonly shortened to *engine*) `e` of type
100
  `E` is a uniform random bit generator that additionally meets the
101
  requirements (e.g., for seeding and for input/output) specified in this
102
+ subclause.
103
 
104
  At any given time, `e` has a state eᵢ for some integer i ≥ 0. Upon
105
  construction, `e` has an initial state e₀. An engine’s state may be
106
  established via a constructor, a `seed` function, assignment, or a
107
  suitable `operator>>`.
108
 
109
  `E`’s specification shall define:
110
 
111
+ - the size of `E`’s state in multiples of the size of `result_type`,
112
+ given as an integral constant expression;
113
+ - the *transition algorithm* TA by which `e`’s state eᵢ is advanced to
114
+ its *successor state* eᵢ₊₁; and
115
+ - the *generation algorithm* GA by which an engine’s state is mapped to
116
+ a value of type `result_type`.
117
+
118
+ A class `E` that meets the requirements of a uniform random bit
119
+ generator [[rand.req.urng]] also meets the requirements of a *random
120
+ number engine* if the expressions shown in [[rand.req.eng]] are valid
121
+ and have the indicated semantics, and if `E` also meets all other
122
+ requirements of this subclause [[rand.req.eng]]. In that Table and
123
+ throughout this subclause:
124
+
125
+ - `T` is the type named by `E`’s associated `result_type`;
126
+ - `e` is a value of `E`, `v` is an lvalue of `E`, `x` and `y` are
127
+ (possibly `const`) values of `E`;
128
+ - `s` is a value of `T`;
129
+ - `q` is an lvalue meeting the requirements of a seed sequence
130
+ [[rand.req.seedseq]];
131
+ - `z` is a value of type `unsigned long long`;
132
+ - `os` is an lvalue of the type of some class template specialization
133
+ `basic_ostream<charT,` `traits>`; and
134
+ - `is` is an lvalue of the type of some class template specialization
135
+ `basic_istream<charT,` `traits>`;
136
+
137
+ where `charT` and `traits` are constrained according to [[strings]] and
138
+ [[input.output]].
139
+
140
+ `E` shall meet the *Cpp17CopyConstructible* (
141
+ [[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
142
+ [[cpp17.copyassignable]]) requirements. These operations shall each be
143
+ of complexity no worse than 𝑂(\text{size of state}).
144
 
145
  #### Random number engine adaptor requirements <a id="rand.req.adapt">[[rand.req.adapt]]</a>
146
 
147
  A *random number engine adaptor* (commonly shortened to *adaptor*) `a`
148
  of type `A` is a random number engine that takes values produced by some
 
197
  template<class Sseq> void seed(Sseq& q);
198
  ```
199
 
200
  *Effects:* With `b` as the base engine, invokes `b.seed(q)`.
201
 
202
+ `A` shall also meet the following additional requirements:
203
+
204
+ - The complexity of each function shall not exceed the complexity of the
205
+ corresponding function applied to the base engine.
206
+ - The state of `A` shall include the state of its base engine. The size
207
+ of `A`’s state shall be no less than the size of the base engine.
208
+ - Copying `A`’s state (e.g., during copy construction or copy
209
+ assignment) shall include copying the state of the base engine of `A`.
210
+ - The textual representation of `A` shall include the textual
211
+ representation of its base engine.
212
 
213
  #### Random number distribution requirements <a id="rand.req.dist">[[rand.req.dist]]</a>
214
 
215
  A *random number distribution* (commonly shortened to *distribution*)
216
  `d` of type `D` is a function object returning values that are
 
225
  context by writing, for example, p(z | a,b) or P(zᵢ | a,b), to name
226
  specific parameters, or by writing, for example, p(z |{`p`}) or
227
  P(zᵢ |{`p`}), to denote a distribution’s parameters `p` taken as a
228
  whole.
229
 
230
+ A class `D` meets the requirements of a *random number distribution* if
231
+ the expressions shown in [[rand.req.dist]] are valid and have the
232
+ indicated semantics, and if `D` and its associated types also meet all
233
+ other requirements of this subclause [[rand.req.dist]]. In that Table
234
+ and throughout this subclause,
235
 
236
+ - `T` is the type named by `D`’s associated `result_type`;
237
+ - `P` is the type named by `D`’s associated `param_type`;
238
+ - `d` is a value of `D`, and `x` and `y` are (possibly `const`) values
239
+ of `D`;
240
+ - `glb` and `lub` are values of `T` respectively corresponding to the
241
+ greatest lower bound and the least upper bound on the values
242
+ potentially returned by `d`’s `operator()`, as determined by the
243
+ current values of `d`’s parameters;
244
+ - `p` is a (possibly `const`) value of `P`;
245
+ - `g`, `g1`, and `g2` are lvalues of a type meeting the requirements of
246
+ a uniform random bit generator [[rand.req.urng]];
247
+ - `os` is an lvalue of the type of some class template specialization
248
+ `basic_ostream<charT,` `traits>`; and
249
+ - `is` is an lvalue of the type of some class template specialization
250
+ `basic_istream<charT,` `traits>`;
251
 
252
+ where `charT` and `traits` are constrained according to [[strings]] and
253
+ [[input.output]].
254
+
255
+ `D` shall meet the *Cpp17CopyConstructible* (
256
+ [[cpp17.copyconstructible]]) and *Cpp17CopyAssignable* (
257
+ [[cpp17.copyassignable]]) requirements.
258
 
259
  The sequence of numbers produced by repeated invocations of `d(g)` shall
260
  be independent of any invocation of `os << d` or of any `const` member
261
  function of `D` between any of the invocations `d(g)`.
262
 
 
269
  It is unspecified whether `D::param_type` is declared as a (nested)
270
  `class` or via a `typedef`. In this subclause [[rand]], declarations of
271
  `D::param_type` are in the form of `typedef`s for convenience of
272
  exposition only.
273
 
274
+ `P` shall meet the *Cpp17CopyConstructible* (
275
+ [[cpp17.copyconstructible]]), *Cpp17CopyAssignable* (
276
+ [[cpp17.copyassignable]]), and *Cpp17EqualityComparable* (
277
+ [[cpp17.equalitycomparable]]) requirements.
278
 
279
  For each of the constructors of `D` taking arguments corresponding to
280
  parameters of the distribution, `P` shall have a corresponding
281
  constructor subject to the same requirements and taking arguments
282
  identical in number, type, and default values. Moreover, for each of the