From Jason Turner

[time.duration]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpf3bv7qpa/{from.md → to.md} +158 -83
tmp/tmpf3bv7qpa/{from.md → to.md} RENAMED
@@ -1,21 +1,24 @@
1
- ### Class template `duration` <a id="time.duration">[[time.duration]]</a>
2
 
3
  A `duration` type measures time between two points in time
4
  (`time_point`s). A `duration` has a representation which holds a count
5
  of ticks and a tick period. The tick period is the amount of time which
6
  occurs from one tick to the next, in units of seconds. It is expressed
7
  as a rational constant using the template `ratio`.
8
 
9
  ``` cpp
 
10
  template<class Rep, class Period = ratio<1>>
11
  class duration {
12
  public:
13
  using rep = Rep;
14
  using period = typename Period::type;
 
15
  private:
16
  rep rep_; // exposition only
 
17
  public:
18
  // [time.duration.cons], construct/copy/destroy
19
  constexpr duration() = default;
20
  template<class Rep2>
21
  constexpr explicit duration(const Rep2& r);
@@ -43,25 +46,26 @@ public:
43
  constexpr duration& operator/=(const rep& rhs);
44
  constexpr duration& operator%=(const rep& rhs);
45
  constexpr duration& operator%=(const duration& rhs);
46
 
47
  // [time.duration.special], special values
48
- static constexpr duration zero();
49
- static constexpr duration min();
50
- static constexpr duration max();
51
  };
 
52
  ```
53
 
54
  `Rep` shall be an arithmetic type or a class emulating an arithmetic
55
  type. If `duration` is instantiated with a `duration` type as the
56
  argument for the template parameter `Rep`, the program is ill-formed.
57
 
58
  If `Period` is not a specialization of `ratio`, the program is
59
  ill-formed. If `Period::num` is not positive, the program is ill-formed.
60
 
61
- Members of `duration` shall not throw exceptions other than those thrown
62
- by the indicated operations on their representations.
63
 
64
  The defaulted copy constructor of duration shall be a constexpr function
65
  if and only if the required initialization of the member `rep_` for copy
66
  and move, respectively, would satisfy the requirements for a constexpr
67
  function.
@@ -75,19 +79,18 @@ duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\fra
75
  // (30 Hz) using a double
76
  ```
77
 
78
  — *end example*]
79
 
80
- #### `duration` constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
81
 
82
  ``` cpp
83
  template<class Rep2>
84
  constexpr explicit duration(const Rep2& r);
85
  ```
86
 
87
- *Remarks:* This constructor shall not participate in overload resolution
88
- unless `Rep2` is implicitly convertible to `rep` and
89
 
90
  - `treat_as_floating_point_v<rep>` is `true` or
91
  - `treat_as_floating_point_v<Rep2>` is `false`.
92
 
93
  [*Example 1*:
@@ -97,21 +100,18 @@ duration<int, milli> d(3); // OK
97
  duration<int, milli> d(3.5); // error
98
  ```
99
 
100
  — *end example*]
101
 
102
- *Effects:* Constructs an object of type `duration`.
103
-
104
- *Postconditions:* `count() == static_cast<rep>(r)`.
105
 
106
  ``` cpp
107
  template<class Rep2, class Period2>
108
  constexpr duration(const duration<Rep2, Period2>& d);
109
  ```
110
 
111
- *Remarks:* This constructor shall not participate in overload resolution
112
- unless no overflow is induced in the conversion and
113
  `treat_as_floating_point_v<rep>` is `true` or both
114
  `ratio_divide<Period2, period>::den` is `1` and
115
  `treat_as_floating_point_v<Rep2>` is `false`.
116
 
117
  [*Note 1*: This requirement prevents implicit truncation error when
@@ -127,23 +127,21 @@ duration<int, micro> us = ms; // OK
127
  duration<int, milli> ms2 = us; // error
128
  ```
129
 
130
  — *end example*]
131
 
132
- *Effects:* Constructs an object of type `duration`, constructing `rep_`
133
- from
134
- `duration_cast<duration>(d).count()`.
135
 
136
- #### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
137
 
138
  ``` cpp
139
  constexpr rep count() const;
140
  ```
141
 
142
  *Returns:* `rep_`.
143
 
144
- #### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
145
 
146
  ``` cpp
147
  constexpr common_type_t<duration> operator+() const;
148
  ```
149
 
@@ -157,106 +155,106 @@ constexpr common_type_t<duration> operator-() const;
157
 
158
  ``` cpp
159
  constexpr duration& operator++();
160
  ```
161
 
162
- *Effects:* As if by `++rep_`.
163
 
164
  *Returns:* `*this`.
165
 
166
  ``` cpp
167
  constexpr duration operator++(int);
168
  ```
169
 
170
- *Returns:* `duration(rep_++)`.
171
 
172
  ``` cpp
173
  constexpr duration& operator--();
174
  ```
175
 
176
- *Effects:* As if by `–rep_`.
177
 
178
  *Returns:* `*this`.
179
 
180
  ``` cpp
181
  constexpr duration operator--(int);
182
  ```
183
 
184
- *Returns:* `duration(rep_--)`.
185
 
186
  ``` cpp
187
  constexpr duration& operator+=(const duration& d);
188
  ```
189
 
190
- *Effects:* As if by: `rep_ += d.count();`
191
 
192
  *Returns:* `*this`.
193
 
194
  ``` cpp
195
  constexpr duration& operator-=(const duration& d);
196
  ```
197
 
198
- *Effects:* As if by: `rep_ -= d.count();`
199
 
200
  *Returns:* `*this`.
201
 
202
  ``` cpp
203
  constexpr duration& operator*=(const rep& rhs);
204
  ```
205
 
206
- *Effects:* As if by: `rep_ *= rhs;`
207
 
208
  *Returns:* `*this`.
209
 
210
  ``` cpp
211
  constexpr duration& operator/=(const rep& rhs);
212
  ```
213
 
214
- *Effects:* As if by: `rep_ /= rhs;`
215
 
216
  *Returns:* `*this`.
217
 
218
  ``` cpp
219
  constexpr duration& operator%=(const rep& rhs);
220
  ```
221
 
222
- *Effects:* As if by: `rep_ %= rhs;`
223
 
224
  *Returns:* `*this`.
225
 
226
  ``` cpp
227
  constexpr duration& operator%=(const duration& rhs);
228
  ```
229
 
230
- *Effects:* As if by: `rep_ %= rhs.count();`
231
 
232
  *Returns:* `*this`.
233
 
234
- #### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
235
 
236
  ``` cpp
237
- static constexpr duration zero();
238
  ```
239
 
240
  *Returns:* `duration(duration_values<rep>::zero())`.
241
 
242
  ``` cpp
243
- static constexpr duration min();
244
  ```
245
 
246
  *Returns:* `duration(duration_values<rep>::min())`.
247
 
248
  ``` cpp
249
- static constexpr duration max();
250
  ```
251
 
252
  *Returns:* `duration(duration_values<rep>::max())`.
253
 
254
- #### `duration` non-member arithmetic <a id="time.duration.nonmember">[[time.duration.nonmember]]</a>
255
 
256
- In the function descriptions that follow, `CD` represents the return
257
- type of the function. `CR(A, B)` represents `common_type_t<A, B>`.
258
 
259
  ``` cpp
260
  template<class Rep1, class Period1, class Rep2, class Period2>
261
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
262
  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
@@ -276,55 +274,58 @@ template <class Rep1, class Period1, class Rep2, class Period2>
276
  template<class Rep1, class Period, class Rep2>
277
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
278
  operator*(const duration<Rep1, Period>& d, const Rep2& s);
279
  ```
280
 
281
- *Remarks:* This operator shall not participate in overload resolution
282
- unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
283
 
284
  *Returns:* `CD(CD(d).count() * s)`.
285
 
286
  ``` cpp
287
  template<class Rep1, class Rep2, class Period>
288
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
289
  operator*(const Rep1& s, const duration<Rep2, Period>& d);
290
  ```
291
 
292
- *Remarks:* This operator shall not participate in overload resolution
293
- unless `Rep1` is implicitly convertible to `CR(Rep1, Rep2)`.
294
 
295
  *Returns:* `d * s`.
296
 
297
  ``` cpp
298
  template<class Rep1, class Period, class Rep2>
299
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
300
  operator/(const duration<Rep1, Period>& d, const Rep2& s);
301
  ```
302
 
303
- *Remarks:* This operator shall not participate in overload resolution
304
- unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
305
- is not a specialization of `duration`.
306
 
307
  *Returns:* `CD(CD(d).count() / s)`.
308
 
309
  ``` cpp
310
  template<class Rep1, class Period1, class Rep2, class Period2>
311
  constexpr common_type_t<Rep1, Rep2>
312
  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
313
  ```
314
 
 
 
 
315
  *Returns:* `CD(lhs).count() / CD(rhs).count()`.
316
 
317
  ``` cpp
318
  template<class Rep1, class Period, class Rep2>
319
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
320
  operator%(const duration<Rep1, Period>& d, const Rep2& s);
321
  ```
322
 
323
- *Remarks:* This operator shall not participate in overload resolution
324
- unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
325
- is not a specialization of `duration`.
326
 
327
  *Returns:* `CD(CD(d).count() % s)`.
328
 
329
  ``` cpp
330
  template<class Rep1, class Period1, class Rep2, class Period2>
@@ -332,11 +333,11 @@ template <class Rep1, class Period1, class Rep2, class Period2>
332
  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
333
  ```
334
 
335
  *Returns:* `CD(CD(lhs).count() % CD(rhs).count())`.
336
 
337
- #### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
338
 
339
  In the function descriptions that follow, `CT` represents
340
  `common_type_t<A, B>`, where `A` and `B` are the types of the two
341
  arguments to the function.
342
 
@@ -344,65 +345,65 @@ arguments to the function.
344
  template<class Rep1, class Period1, class Rep2, class Period2>
345
  constexpr bool operator==(const duration<Rep1, Period1>& lhs,
346
  const duration<Rep2, Period2>& rhs);
347
  ```
348
 
349
- *Returns:* *`CT`*`(lhs).count() == `*`CT`*`(rhs).count()`.
350
-
351
- ``` cpp
352
- template <class Rep1, class Period1, class Rep2, class Period2>
353
- constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
354
- const duration<Rep2, Period2>& rhs);
355
- ```
356
-
357
- *Returns:* `!(lhs == rhs)`.
358
 
359
  ``` cpp
360
  template<class Rep1, class Period1, class Rep2, class Period2>
361
  constexpr bool operator<(const duration<Rep1, Period1>& lhs,
362
  const duration<Rep2, Period2>& rhs);
363
  ```
364
 
365
- *Returns:* *`CT`*`(lhs).count() < `*`CT`*`(rhs).count()`.
366
-
367
- ``` cpp
368
- template <class Rep1, class Period1, class Rep2, class Period2>
369
- constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
370
- const duration<Rep2, Period2>& rhs);
371
- ```
372
-
373
- *Returns:* `!(rhs < lhs)`.
374
 
375
  ``` cpp
376
  template<class Rep1, class Period1, class Rep2, class Period2>
377
  constexpr bool operator>(const duration<Rep1, Period1>& lhs,
378
  const duration<Rep2, Period2>& rhs);
379
  ```
380
 
381
  *Returns:* `rhs < lhs`.
382
 
 
 
 
 
 
 
 
 
383
  ``` cpp
384
  template<class Rep1, class Period1, class Rep2, class Period2>
385
  constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
386
  const duration<Rep2, Period2>& rhs);
387
  ```
388
 
389
  *Returns:* `!(lhs < rhs)`.
390
 
391
- #### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
 
 
 
 
 
 
 
 
 
392
 
393
  ``` cpp
394
  template<class ToDuration, class Rep, class Period>
395
  constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
396
  ```
397
 
398
- *Remarks:* This function shall not participate in overload resolution
399
- unless `ToDuration` is a specialization of `duration`.
400
 
401
  *Returns:* Let `CF` be
402
  `ratio_divide<Period, typename ToDuration::period>`, and `CR` be
403
- `common_type<` `typename ToDuration::rep, Rep, intmax_t>::type`.
404
 
405
  - If `CF::num == 1` and `CF::den == 1`, returns
406
  ``` cpp
407
  ToDuration(static_cast<typename ToDuration::rep>(d.count()))
408
  ```
@@ -432,53 +433,50 @@ the final step. — *end note*]
432
  ``` cpp
433
  template<class ToDuration, class Rep, class Period>
434
  constexpr ToDuration floor(const duration<Rep, Period>& d);
435
  ```
436
 
437
- *Remarks:* This function shall not participate in overload resolution
438
- unless `ToDuration` is a specialization of `duration`.
439
 
440
  *Returns:* The greatest result `t` representable in `ToDuration` for
441
  which `t <= d`.
442
 
443
  ``` cpp
444
  template<class ToDuration, class Rep, class Period>
445
  constexpr ToDuration ceil(const duration<Rep, Period>& d);
446
  ```
447
 
448
- *Remarks:* This function shall not participate in overload resolution
449
- unless `ToDuration` is a specialization of `duration`.
450
 
451
  *Returns:* The least result `t` representable in `ToDuration` for which
452
  `t >= d`.
453
 
454
  ``` cpp
455
  template<class ToDuration, class Rep, class Period>
456
  constexpr ToDuration round(const duration<Rep, Period>& d);
457
  ```
458
 
459
- *Remarks:* This function shall not participate in overload resolution
460
- unless `ToDuration` is a specialization of `duration`, and
461
  `treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
462
 
463
  *Returns:* The value of `ToDuration` that is closest to `d`. If there
464
  are two closest values, then return the value `t` for which
465
  `t % 2 == 0`.
466
 
467
- #### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
468
 
469
- This section describes literal suffixes for constructing duration
470
  literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
471
  values of the corresponding types `hours`, `minutes`, `seconds`,
472
  `milliseconds`, `microseconds`, and `nanoseconds` respectively if they
473
- are applied to integral literals.
474
 
475
- If any of these suffixes are applied to a floating-point literal the
476
  result is a `chrono::duration` literal with an unspecified
477
  floating-point representation.
478
 
479
- If any of these suffixes are applied to an integer literal and the
480
  resulting `chrono::duration` value cannot be represented in the result
481
  type because of overflow, the program is ill-formed.
482
 
483
  [*Example 1*:
484
 
@@ -537,17 +535,94 @@ constexpr chrono::nanoseconds operator""ns(unsigned long long ns
537
  constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
538
  ```
539
 
540
  *Returns:* A `duration` literal representing `nsec` nanoseconds.
541
 
542
- #### `duration` algorithms <a id="time.duration.alg">[[time.duration.alg]]</a>
543
 
544
  ``` cpp
545
  template<class Rep, class Period>
546
  constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
547
  ```
548
 
549
- *Remarks:* This function shall not participate in overload resolution
550
- unless `numeric_limits<Rep>::is_signed` is `true`.
551
 
552
  *Returns:* If `d >= d.zero()`, return `d`, otherwise return `-d`.
553
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Class template `duration` <a id="time.duration">[[time.duration]]</a>
2
 
3
  A `duration` type measures time between two points in time
4
  (`time_point`s). A `duration` has a representation which holds a count
5
  of ticks and a tick period. The tick period is the amount of time which
6
  occurs from one tick to the next, in units of seconds. It is expressed
7
  as a rational constant using the template `ratio`.
8
 
9
  ``` cpp
10
+ namespace std::chrono {
11
  template<class Rep, class Period = ratio<1>>
12
  class duration {
13
  public:
14
  using rep = Rep;
15
  using period = typename Period::type;
16
+
17
  private:
18
  rep rep_; // exposition only
19
+
20
  public:
21
  // [time.duration.cons], construct/copy/destroy
22
  constexpr duration() = default;
23
  template<class Rep2>
24
  constexpr explicit duration(const Rep2& r);
 
46
  constexpr duration& operator/=(const rep& rhs);
47
  constexpr duration& operator%=(const rep& rhs);
48
  constexpr duration& operator%=(const duration& rhs);
49
 
50
  // [time.duration.special], special values
51
+ static constexpr duration zero() noexcept;
52
+ static constexpr duration min() noexcept;
53
+ static constexpr duration max() noexcept;
54
  };
55
+ }
56
  ```
57
 
58
  `Rep` shall be an arithmetic type or a class emulating an arithmetic
59
  type. If `duration` is instantiated with a `duration` type as the
60
  argument for the template parameter `Rep`, the program is ill-formed.
61
 
62
  If `Period` is not a specialization of `ratio`, the program is
63
  ill-formed. If `Period::num` is not positive, the program is ill-formed.
64
 
65
+ Members of `duration` do not throw exceptions other than those thrown by
66
+ the indicated operations on their representations.
67
 
68
  The defaulted copy constructor of duration shall be a constexpr function
69
  if and only if the required initialization of the member `rep_` for copy
70
  and move, respectively, would satisfy the requirements for a constexpr
71
  function.
 
79
  // (30 Hz) using a double
80
  ```
81
 
82
  — *end example*]
83
 
84
+ ### Constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
85
 
86
  ``` cpp
87
  template<class Rep2>
88
  constexpr explicit duration(const Rep2& r);
89
  ```
90
 
91
+ *Constraints:* `is_convertible_v<const Rep2&, rep>` is `true` and
 
92
 
93
  - `treat_as_floating_point_v<rep>` is `true` or
94
  - `treat_as_floating_point_v<Rep2>` is `false`.
95
 
96
  [*Example 1*:
 
100
  duration<int, milli> d(3.5); // error
101
  ```
102
 
103
  — *end example*]
104
 
105
+ *Ensures:* `count() == static_cast<rep>(r)`.
 
 
106
 
107
  ``` cpp
108
  template<class Rep2, class Period2>
109
  constexpr duration(const duration<Rep2, Period2>& d);
110
  ```
111
 
112
+ *Constraints:* No overflow is induced in the conversion and
 
113
  `treat_as_floating_point_v<rep>` is `true` or both
114
  `ratio_divide<Period2, period>::den` is `1` and
115
  `treat_as_floating_point_v<Rep2>` is `false`.
116
 
117
  [*Note 1*: This requirement prevents implicit truncation error when
 
127
  duration<int, milli> ms2 = us; // error
128
  ```
129
 
130
  — *end example*]
131
 
132
+ *Effects:* Initializes `rep_` with `duration_cast<duration>(d).count()`.
 
 
133
 
134
+ ### Observer <a id="time.duration.observer">[[time.duration.observer]]</a>
135
 
136
  ``` cpp
137
  constexpr rep count() const;
138
  ```
139
 
140
  *Returns:* `rep_`.
141
 
142
+ ### Arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
143
 
144
  ``` cpp
145
  constexpr common_type_t<duration> operator+() const;
146
  ```
147
 
 
155
 
156
  ``` cpp
157
  constexpr duration& operator++();
158
  ```
159
 
160
+ *Effects:* Equivalent to: `++rep_`.
161
 
162
  *Returns:* `*this`.
163
 
164
  ``` cpp
165
  constexpr duration operator++(int);
166
  ```
167
 
168
+ *Effects:* Equivalent to: `return duration(rep_++);`
169
 
170
  ``` cpp
171
  constexpr duration& operator--();
172
  ```
173
 
174
+ *Effects:* Equivalent to: `–rep_`.
175
 
176
  *Returns:* `*this`.
177
 
178
  ``` cpp
179
  constexpr duration operator--(int);
180
  ```
181
 
182
+ *Effects:* Equivalent to: `return duration(rep_--);`
183
 
184
  ``` cpp
185
  constexpr duration& operator+=(const duration& d);
186
  ```
187
 
188
+ *Effects:* Equivalent to: `rep_ += d.count()`.
189
 
190
  *Returns:* `*this`.
191
 
192
  ``` cpp
193
  constexpr duration& operator-=(const duration& d);
194
  ```
195
 
196
+ *Effects:* Equivalent to: `rep_ -= d.count()`.
197
 
198
  *Returns:* `*this`.
199
 
200
  ``` cpp
201
  constexpr duration& operator*=(const rep& rhs);
202
  ```
203
 
204
+ *Effects:* Equivalent to: `rep_ *= rhs`.
205
 
206
  *Returns:* `*this`.
207
 
208
  ``` cpp
209
  constexpr duration& operator/=(const rep& rhs);
210
  ```
211
 
212
+ *Effects:* Equivalent to: `rep_ /= rhs`.
213
 
214
  *Returns:* `*this`.
215
 
216
  ``` cpp
217
  constexpr duration& operator%=(const rep& rhs);
218
  ```
219
 
220
+ *Effects:* Equivalent to: `rep_ %= rhs`.
221
 
222
  *Returns:* `*this`.
223
 
224
  ``` cpp
225
  constexpr duration& operator%=(const duration& rhs);
226
  ```
227
 
228
+ *Effects:* Equivalent to: `rep_ %= rhs.count()`.
229
 
230
  *Returns:* `*this`.
231
 
232
+ ### Special values <a id="time.duration.special">[[time.duration.special]]</a>
233
 
234
  ``` cpp
235
+ static constexpr duration zero() noexcept;
236
  ```
237
 
238
  *Returns:* `duration(duration_values<rep>::zero())`.
239
 
240
  ``` cpp
241
+ static constexpr duration min() noexcept;
242
  ```
243
 
244
  *Returns:* `duration(duration_values<rep>::min())`.
245
 
246
  ``` cpp
247
+ static constexpr duration max() noexcept;
248
  ```
249
 
250
  *Returns:* `duration(duration_values<rep>::max())`.
251
 
252
+ ### Non-member arithmetic <a id="time.duration.nonmember">[[time.duration.nonmember]]</a>
253
 
254
+ In the function descriptions that follow, unless stated otherwise, let
255
+ `CD` represent the return type of the function.
256
 
257
  ``` cpp
258
  template<class Rep1, class Period1, class Rep2, class Period2>
259
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
260
  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
274
  template<class Rep1, class Period, class Rep2>
275
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
276
  operator*(const duration<Rep1, Period>& d, const Rep2& s);
277
  ```
278
 
279
+ *Constraints:*
280
+ `is_convertible_v<const Rep2&, common_type_t<Rep1, Rep2>>` is `true`.
281
 
282
  *Returns:* `CD(CD(d).count() * s)`.
283
 
284
  ``` cpp
285
  template<class Rep1, class Rep2, class Period>
286
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
287
  operator*(const Rep1& s, const duration<Rep2, Period>& d);
288
  ```
289
 
290
+ *Constraints:*
291
+ `is_convertible_v<const Rep1&, common_type_t<Rep1, Rep2>>` is `true`.
292
 
293
  *Returns:* `d * s`.
294
 
295
  ``` cpp
296
  template<class Rep1, class Period, class Rep2>
297
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
298
  operator/(const duration<Rep1, Period>& d, const Rep2& s);
299
  ```
300
 
301
+ *Constraints:*
302
+ `is_convertible_v<const Rep2&, common_type_t<Rep1, Rep2>>` is `true` and
303
+ `Rep2` is not a specialization of `duration`.
304
 
305
  *Returns:* `CD(CD(d).count() / s)`.
306
 
307
  ``` cpp
308
  template<class Rep1, class Period1, class Rep2, class Period2>
309
  constexpr common_type_t<Rep1, Rep2>
310
  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
311
  ```
312
 
313
+ Let `CD` be
314
+ `common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>`.
315
+
316
  *Returns:* `CD(lhs).count() / CD(rhs).count()`.
317
 
318
  ``` cpp
319
  template<class Rep1, class Period, class Rep2>
320
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
321
  operator%(const duration<Rep1, Period>& d, const Rep2& s);
322
  ```
323
 
324
+ *Constraints:*
325
+ `is_convertible_v<const Rep2&, common_type_t<Rep1, Rep2>>` is `true` and
326
+ `Rep2` is not a specialization of `duration`.
327
 
328
  *Returns:* `CD(CD(d).count() % s)`.
329
 
330
  ``` cpp
331
  template<class Rep1, class Period1, class Rep2, class Period2>
 
333
  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
334
  ```
335
 
336
  *Returns:* `CD(CD(lhs).count() % CD(rhs).count())`.
337
 
338
+ ### Comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
339
 
340
  In the function descriptions that follow, `CT` represents
341
  `common_type_t<A, B>`, where `A` and `B` are the types of the two
342
  arguments to the function.
343
 
 
345
  template<class Rep1, class Period1, class Rep2, class Period2>
346
  constexpr bool operator==(const duration<Rep1, Period1>& lhs,
347
  const duration<Rep2, Period2>& rhs);
348
  ```
349
 
350
+ *Returns:* `CT(lhs).count() == CT(rhs).count()`.
 
 
 
 
 
 
 
 
351
 
352
  ``` cpp
353
  template<class Rep1, class Period1, class Rep2, class Period2>
354
  constexpr bool operator<(const duration<Rep1, Period1>& lhs,
355
  const duration<Rep2, Period2>& rhs);
356
  ```
357
 
358
+ *Returns:* `CT(lhs).count() < CT(rhs).count()`.
 
 
 
 
 
 
 
 
359
 
360
  ``` cpp
361
  template<class Rep1, class Period1, class Rep2, class Period2>
362
  constexpr bool operator>(const duration<Rep1, Period1>& lhs,
363
  const duration<Rep2, Period2>& rhs);
364
  ```
365
 
366
  *Returns:* `rhs < lhs`.
367
 
368
+ ``` cpp
369
+ template<class Rep1, class Period1, class Rep2, class Period2>
370
+ constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
371
+ const duration<Rep2, Period2>& rhs);
372
+ ```
373
+
374
+ *Returns:* `!(rhs < lhs)`.
375
+
376
  ``` cpp
377
  template<class Rep1, class Period1, class Rep2, class Period2>
378
  constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
379
  const duration<Rep2, Period2>& rhs);
380
  ```
381
 
382
  *Returns:* `!(lhs < rhs)`.
383
 
384
+ ``` cpp
385
+ template<class Rep1, class Period1, class Rep2, class Period2>
386
+ requires three_way_comparable<typename CT::rep>
387
+ constexpr auto operator<=>(const duration<Rep1, Period1>& lhs,
388
+ const duration<Rep2, Period2>& rhs);
389
+ ```
390
+
391
+ *Returns:* `CT(lhs).count() <=> CT(rhs).count()`.
392
+
393
+ ### Conversions <a id="time.duration.cast">[[time.duration.cast]]</a>
394
 
395
  ``` cpp
396
  template<class ToDuration, class Rep, class Period>
397
  constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
398
  ```
399
 
400
+ *Constraints:* `ToDuration` is a specialization of `duration`.
 
401
 
402
  *Returns:* Let `CF` be
403
  `ratio_divide<Period, typename ToDuration::period>`, and `CR` be
404
+ `common_type<typename ToDuration::rep, Rep, intmax_t>::type`.
405
 
406
  - If `CF::num == 1` and `CF::den == 1`, returns
407
  ``` cpp
408
  ToDuration(static_cast<typename ToDuration::rep>(d.count()))
409
  ```
 
433
  ``` cpp
434
  template<class ToDuration, class Rep, class Period>
435
  constexpr ToDuration floor(const duration<Rep, Period>& d);
436
  ```
437
 
438
+ *Constraints:* `ToDuration` is a specialization of `duration`.
 
439
 
440
  *Returns:* The greatest result `t` representable in `ToDuration` for
441
  which `t <= d`.
442
 
443
  ``` cpp
444
  template<class ToDuration, class Rep, class Period>
445
  constexpr ToDuration ceil(const duration<Rep, Period>& d);
446
  ```
447
 
448
+ *Constraints:* `ToDuration` is a specialization of `duration`.
 
449
 
450
  *Returns:* The least result `t` representable in `ToDuration` for which
451
  `t >= d`.
452
 
453
  ``` cpp
454
  template<class ToDuration, class Rep, class Period>
455
  constexpr ToDuration round(const duration<Rep, Period>& d);
456
  ```
457
 
458
+ *Constraints:* `ToDuration` is a specialization of `duration` and
 
459
  `treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
460
 
461
  *Returns:* The value of `ToDuration` that is closest to `d`. If there
462
  are two closest values, then return the value `t` for which
463
  `t % 2 == 0`.
464
 
465
+ ### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
466
 
467
+ This subclause describes literal suffixes for constructing duration
468
  literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
469
  values of the corresponding types `hours`, `minutes`, `seconds`,
470
  `milliseconds`, `microseconds`, and `nanoseconds` respectively if they
471
+ are applied to *integer-literal*s.
472
 
473
+ If any of these suffixes are applied to a *floating-point-literal* the
474
  result is a `chrono::duration` literal with an unspecified
475
  floating-point representation.
476
 
477
+ If any of these suffixes are applied to an *integer-literal* and the
478
  resulting `chrono::duration` value cannot be represented in the result
479
  type because of overflow, the program is ill-formed.
480
 
481
  [*Example 1*:
482
 
 
535
  constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
536
  ```
537
 
538
  *Returns:* A `duration` literal representing `nsec` nanoseconds.
539
 
540
+ ### Algorithms <a id="time.duration.alg">[[time.duration.alg]]</a>
541
 
542
  ``` cpp
543
  template<class Rep, class Period>
544
  constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
545
  ```
546
 
547
+ *Constraints:* `numeric_limits<Rep>::is_signed` is `true`.
 
548
 
549
  *Returns:* If `d >= d.zero()`, return `d`, otherwise return `-d`.
550
 
551
+ ### I/O <a id="time.duration.io">[[time.duration.io]]</a>
552
+
553
+ ``` cpp
554
+ template<class charT, class traits, class Rep, class Period>
555
+ basic_ostream<charT, traits>&
556
+ operator<<(basic_ostream<charT, traits>& os, const duration<Rep, Period>& d);
557
+ ```
558
+
559
+ *Effects:* Inserts the duration `d` onto the stream `os` as if it were
560
+ implemented as follows:
561
+
562
+ ``` cpp
563
+ basic_ostringstream<charT, traits> s;
564
+ s.flags(os.flags());
565
+ s.imbue(os.getloc());
566
+ s.precision(os.precision());
567
+ s << d.count() << units-suffix;
568
+ return os << s.str();
569
+ ```
570
+
571
+ where *`units-suffix`* depends on the type `Period::type` as follows:
572
+
573
+ - If `Period::type` is `atto`, *`units-suffix`* is `"as"`.
574
+ - Otherwise, if `Period::type` is `femto`, *`units-suffix`* is `"fs"`.
575
+ - Otherwise, if `Period::type` is `pico`, *`units-suffix`* is `"ps"`.
576
+ - Otherwise, if `Period::type` is `nano`, *`units-suffix`* is `"ns"`.
577
+ - Otherwise, if `Period::type` is `micro`, it is
578
+ *implementation-defined* whether *`units-suffix`* is `"`\textmu`s"`
579
+ (`"\u00b5\u0073"`) or `"us"`.
580
+ - Otherwise, if `Period::type` is `milli`, *`units-suffix`* is `"ms"`.
581
+ - Otherwise, if `Period::type` is `centi`, *`units-suffix`* is `"cs"`.
582
+ - Otherwise, if `Period::type` is `deci`, *`units-suffix`* is `"ds"`.
583
+ - Otherwise, if `Period::type` is `ratio<1>`, *`units-suffix`* is `"s"`.
584
+ - Otherwise, if `Period::type` is `deca`, *`units-suffix`* is `"das"`.
585
+ - Otherwise, if `Period::type` is `hecto`, *`units-suffix`* is `"hs"`.
586
+ - Otherwise, if `Period::type` is `kilo`, *`units-suffix`* is `"ks"`.
587
+ - Otherwise, if `Period::type` is `mega`, *`units-suffix`* is `"Ms"`.
588
+ - Otherwise, if `Period::type` is `giga`, *`units-suffix`* is `"Gs"`.
589
+ - Otherwise, if `Period::type` is `tera`, *`units-suffix`* is `"Ts"`.
590
+ - Otherwise, if `Period::type` is `peta`, *`units-suffix`* is `"Ps"`.
591
+ - Otherwise, if `Period::type` is `exa`, *`units-suffix`* is `"Es"`.
592
+ - Otherwise, if `Period::type` is `ratio<60>`, *`units-suffix`* is
593
+ `"min"`.
594
+ - Otherwise, if `Period::type` is `ratio<3600>`, *`units-suffix`* is
595
+ `"h"`.
596
+ - Otherwise, if `Period::type` is `ratio<86400>`, *`units-suffix`* is
597
+ `"d"`.
598
+ - Otherwise, if `Period::type::den == 1`, *`units-suffix`* is
599
+ `"[`*`num`*`]s"`.
600
+ - Otherwise, *`units-suffix`* is `"[`*`num`*`/`*`den`*`]s"`.
601
+
602
+ In the list above, the use of *`num`* and *`den`* refer to the static
603
+ data members of `Period::type`, which are converted to arrays of `charT`
604
+ using a decimal conversion with no leading zeroes.
605
+
606
+ *Returns:* `os`.
607
+
608
+ ``` cpp
609
+ template<class charT, class traits, class Rep, class Period, class Alloc = allocator<charT>>
610
+ basic_istream<charT, traits>&
611
+ from_stream(basic_istream<charT, traits>& is, const charT* fmt,
612
+ duration<Rep, Period>& d,
613
+ basic_string<charT, traits, Alloc>* abbrev = nullptr,
614
+ minutes* offset = nullptr);
615
+ ```
616
+
617
+ *Effects:* Attempts to parse the input stream `is` into the duration `d`
618
+ using the format flags given in the NTCTS `fmt` as specified in
619
+ [[time.parse]]. If the parse parses everything specified by the parsing
620
+ format flags without error, and yet none of the flags impacts a
621
+ duration, `d` will be assigned a zero value. If `%Z` is used and
622
+ successfully parsed, that value will be assigned to `*abbrev` if
623
+ `abbrev` is non-null. If `%z` (or a modified variant) is used and
624
+ successfully parsed, that value will be assigned to `*offset` if
625
+ `offset` is non-null.
626
+
627
+ *Returns:* `is`.
628
+