From Jason Turner

[time.duration]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpkknhaxxn/{from.md → to.md} +158 -91
tmp/tmpkknhaxxn/{from.md → to.md} RENAMED
@@ -8,119 +8,129 @@ 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
- typedef Rep rep;
14
- typedef Period period;
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);
22
  template <class Rep2, class Period2>
23
  constexpr duration(const duration<Rep2, Period2>& d);
24
  ~duration() = default;
25
  duration(const duration&) = default;
26
  duration& operator=(const duration&) = default;
27
 
28
- // [time.duration.observer], observer:
29
  constexpr rep count() const;
30
 
31
- // [time.duration.arithmetic], arithmetic:
32
- constexpr duration operator+() const;
33
- constexpr duration operator-() const;
34
- duration& operator++();
35
- duration operator++(int);
36
- duration& operator--();
37
- duration operator--(int);
38
 
39
- duration& operator+=(const duration& d);
40
- duration& operator-=(const duration& d);
41
 
42
- duration& operator*=(const rep& rhs);
43
- duration& operator/=(const rep& rhs);
44
- duration& operator%=(const rep& rhs);
45
- 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
- *Requires:* `Rep` shall be an arithmetic type or a class emulating an
55
- arithmetic type.
 
56
 
57
- *Remarks:* If `duration` is instantiated with a `duration` type for the
58
- template argument `Rep`, the program is ill-formed.
59
 
60
- *Remarks:* If `Period` is not a specialization of `ratio`, the program
61
- is ill-formed.
62
 
63
- *Remarks:* If `Period::num` is not positive, the program is ill-formed.
 
 
 
64
 
65
- *Requires:* Members of `duration` shall not throw exceptions other than
66
- those thrown by the indicated operations on their representations.
67
-
68
- *Remarks:* The defaulted copy constructor of duration shall be a
69
- `constexpr` function if and only if the required initialization of the
70
- member `rep_` for copy and move, respectively, would satisfy the
71
- requirements for a `constexpr` function.
72
 
73
  ``` cpp
74
  duration<long, ratio<60>> d0; // holds a count of minutes using a long
75
  duration<long long, milli> d1; // holds a count of milliseconds using a long long
76
  duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
77
  // (30 Hz) using a double
78
  ```
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<rep>::value` is `true` or
91
- - `treat_as_floating_point<Rep2>::value` is `false`.
 
 
92
 
93
  ``` cpp
94
  duration<int, milli> d(3); // OK
95
  duration<int, milli> d(3.5); // error
96
  ```
97
 
 
 
98
  *Effects:* Constructs an object of type `duration`.
99
 
100
- `count() == static_cast<rep>(r)`.
101
 
102
  ``` cpp
103
  template <class Rep2, class Period2>
104
  constexpr duration(const duration<Rep2, Period2>& d);
105
  ```
106
 
107
  *Remarks:* This constructor shall not participate in overload resolution
108
  unless no overflow is induced in the conversion and
109
- `treat_as_floating_point<rep>::value` is `true` or both
110
  `ratio_divide<Period2, period>::den` is `1` and
111
- `treat_as_floating_point<Rep2>::value` is `false`. This requirement
112
- prevents implicit truncation error when converting between
113
- integral-based `duration` types. Such a construction could easily lead
114
- to confusion about the value of the `duration`.
 
 
 
 
115
 
116
  ``` cpp
117
  duration<int, milli> ms(3);
118
  duration<int, micro> us = ms; // OK
119
  duration<int, milli> ms2 = us; // error
120
  ```
121
 
 
 
122
  *Effects:* Constructs an object of type `duration`, constructing `rep_`
123
  from
124
  `duration_cast<duration>(d).count()`.
125
 
126
  #### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
@@ -132,94 +142,94 @@ constexpr rep count() const;
132
  *Returns:* `rep_`.
133
 
134
  #### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
135
 
136
  ``` cpp
137
- constexpr duration operator+() const;
138
  ```
139
 
140
- *Returns:* `*this`.
141
 
142
  ``` cpp
143
- constexpr duration operator-() const;
144
  ```
145
 
146
- *Returns:* `duration(-rep_);`.
147
 
148
  ``` cpp
149
- duration& operator++();
150
  ```
151
 
152
- *Effects:* `++rep_`.
153
 
154
  *Returns:* `*this`.
155
 
156
  ``` cpp
157
- duration operator++(int);
158
  ```
159
 
160
- *Returns:* `duration(rep_++);`.
161
 
162
  ``` cpp
163
- duration& operator--();
164
  ```
165
 
166
- *Effects:* `-``-``rep_`.
167
 
168
  *Returns:* `*this`.
169
 
170
  ``` cpp
171
- duration operator--(int);
172
  ```
173
 
174
- *Returns:* `duration(rep_--);`.
175
 
176
  ``` cpp
177
- duration& operator+=(const duration& d);
178
  ```
179
 
180
- *Effects:* `rep_ += d.count()`.
181
 
182
  *Returns:* `*this`.
183
 
184
  ``` cpp
185
- duration& operator-=(const duration& d);
186
  ```
187
 
188
- *Effects:* `rep_ -= d.count()`.
189
 
190
  *Returns:* `*this`.
191
 
192
  ``` cpp
193
- duration& operator*=(const rep& rhs);
194
  ```
195
 
196
- *Effects:* `rep_ *= rhs`.
197
 
198
  *Returns:* `*this`.
199
 
200
  ``` cpp
201
- duration& operator/=(const rep& rhs);
202
  ```
203
 
204
- *Effects:* `rep_ /= rhs`.
205
 
206
  *Returns:* `*this`.
207
 
208
  ``` cpp
209
- duration& operator%=(const rep& rhs);
210
  ```
211
 
212
- *Effects:* `rep_ %= rhs`.
213
 
214
  *Returns:* `*this`.
215
 
216
  ``` cpp
217
- duration& operator%=(const duration& rhs);
218
  ```
219
 
220
- *Effects:* `rep_ %= rhs.count()`.
221
 
222
  *Returns:* `*this`.
223
 
224
  #### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
225
 
@@ -250,30 +260,30 @@ type of the function. `CR(A,B)` represents `common_type_t<A, B>`.
250
  template <class Rep1, class Period1, class Rep2, class Period2>
251
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
252
  operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
253
  ```
254
 
255
- *Returns:* CD(CD(lhs).count() + CD(rhs).count()).
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);
261
  ```
262
 
263
- *Returns:* CD(CD(lhs).count() - CD(rhs).count()).
264
 
265
  ``` cpp
266
  template <class Rep1, class Period, class Rep2>
267
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
268
  operator*(const duration<Rep1, Period>& d, const Rep2& s);
269
  ```
270
 
271
  *Remarks:* This operator shall not participate in overload resolution
272
  unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
273
 
274
- *Returns:* CD(CD(d).count() \* s).
275
 
276
  ``` cpp
277
  template <class Rep1, class Rep2, class Period>
278
  constexpr duration<common_type_t<Rep1, Rep2>, Period>
279
  operator*(const Rep1& s, const duration<Rep2, Period>& d);
@@ -290,13 +300,13 @@ template <class Rep1, class Period, class Rep2>
290
  operator/(const duration<Rep1, Period>& d, const Rep2& s);
291
  ```
292
 
293
  *Remarks:* This operator shall not participate in overload resolution
294
  unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
295
- is not an instantiation of `duration`.
296
 
297
- *Returns:* CD(CD(d).count() / s).
298
 
299
  ``` cpp
300
  template <class Rep1, class Period1, class Rep2, class Period2>
301
  constexpr common_type_t<Rep1, Rep2>
302
  operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
@@ -310,66 +320,72 @@ template <class Rep1, class Period, class Rep2>
310
  operator%(const duration<Rep1, Period>& d, const Rep2& s);
311
  ```
312
 
313
  *Remarks:* This operator shall not participate in overload resolution
314
  unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
315
- is not an instantiation of `duration`.
316
 
317
- *Returns:* CD(CD(d).count() % s).
318
 
319
  ``` cpp
320
  template <class Rep1, class Period1, class Rep2, class Period2>
321
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
322
  operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
323
  ```
324
 
325
- *Returns:* CD(CD(lhs).count() % CD(rhs).count()).
326
 
327
  #### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
328
 
329
  In the function descriptions that follow, `CT` represents
330
  `common_type_t<A, B>`, where `A` and `B` are the types of the two
331
  arguments to the function.
332
 
333
  ``` cpp
334
  template <class Rep1, class Period1, class Rep2, class Period2>
335
- constexpr bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
336
  ```
337
 
338
- *Returns:* `CT(lhs).count() == CT(rhs).count()`.
339
 
340
  ``` cpp
341
  template <class Rep1, class Period1, class Rep2, class Period2>
342
- constexpr bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
343
  ```
344
 
345
  *Returns:* `!(lhs == rhs)`.
346
 
347
  ``` cpp
348
  template <class Rep1, class Period1, class Rep2, class Period2>
349
- constexpr bool operator<(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
350
  ```
351
 
352
- *Returns:* `CT(lhs).count() < CT(rhs).count()`.
353
 
354
  ``` cpp
355
  template <class Rep1, class Period1, class Rep2, class Period2>
356
- constexpr bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
 
357
  ```
358
 
359
  *Returns:* `!(rhs < lhs)`.
360
 
361
  ``` cpp
362
  template <class Rep1, class Period1, class Rep2, class Period2>
363
- constexpr bool operator>(const duration<Rep1, Period1>& lhs, 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, const duration<Rep2, Period2>& rhs);
 
371
  ```
372
 
373
  *Returns:* `!(lhs < rhs)`.
374
 
375
  #### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
@@ -378,15 +394,15 @@ template <class Rep1, class Period1, class Rep2, class Period2>
378
  template <class ToDuration, class Rep, class Period>
379
  constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
380
  ```
381
 
382
  *Remarks:* This function shall not participate in overload resolution
383
- unless `ToDuration` is an instantiation of `duration`.
384
 
385
  *Returns:* Let `CF` be
386
  `ratio_divide<Period, typename ToDuration::period>`, and `CR` be
387
- `common_type<` `typename ToDuration::rep, Rep, intmax_t>::type.`
388
 
389
  - If `CF::num == 1` and `CF::den == 1`, returns
390
  ``` cpp
391
  ToDuration(static_cast<typename ToDuration::rep>(d.count()))
392
  ```
@@ -404,42 +420,81 @@ unless `ToDuration` is an instantiation of `duration`.
404
  ``` cpp
405
  ToDuration(static_cast<typename ToDuration::rep>(
406
  static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
407
  ```
408
 
409
- *Notes:* This function does not use any implicit conversions; all
410
  conversions are done with `static_cast`. It avoids multiplications and
411
  divisions when it is known at compile time that one or more arguments
412
  is 1. Intermediate computations are carried out in the widest
413
  representation and only converted to the destination representation at
414
- the final step.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
 
416
  #### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
417
 
418
  This section describes literal suffixes for constructing duration
419
  literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
420
  values of the corresponding types `hours`, `minutes`, `seconds`,
421
  `milliseconds`, `microseconds`, and `nanoseconds` respectively if they
422
  are applied to integral literals.
423
 
424
- If any of these suffixes are applied to a floating point literal the
425
- result is a `chrono::duration` literal with an unspecified floating
426
- point representation.
427
 
428
  If any of these suffixes are applied to an integer literal and the
429
  resulting `chrono::duration` value cannot be represented in the result
430
  type because of overflow, the program is ill-formed.
431
 
 
 
432
  The following code shows some duration literals.
433
 
434
  ``` cpp
435
  using namespace std::chrono_literals;
436
  auto constexpr aday=24h;
437
  auto constexpr lesson=45min;
438
  auto constexpr halfanhour=0.5h;
439
  ```
440
 
 
 
441
  ``` cpp
442
  constexpr chrono::hours operator""h(unsigned long long hours);
443
  constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
444
  ```
445
 
@@ -451,19 +506,19 @@ constexpr chrono::duration<unspecified, ratio<60,1>> operator "" min(long double
451
  ```
452
 
453
  *Returns:* A `duration` literal representing `minutes` minutes.
454
 
455
  ``` cpp
456
- constexpr chrono::seconds operator "" s(unsigned long long sec);
457
  constexpr chrono::duration<unspecified> operator""s(long double sec);
458
  ```
459
 
460
  *Returns:* A `duration` literal representing `sec` seconds.
461
 
462
- The same suffix `s` is used for `basic_string` but there is no conflict,
463
- since duration suffixes apply to numbers and string literal suffixes
464
- apply to character array literals.
465
 
466
  ``` cpp
467
  constexpr chrono::milliseconds operator""ms(unsigned long long msec);
468
  constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
469
  ```
@@ -482,5 +537,17 @@ constexpr chrono::nanoseconds operator "" ns(unsigned long long
482
  constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
483
  ```
484
 
485
  *Returns:* A `duration` literal representing `nsec` nanoseconds.
486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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);
22
  template <class Rep2, class Period2>
23
  constexpr duration(const duration<Rep2, Period2>& d);
24
  ~duration() = default;
25
  duration(const duration&) = default;
26
  duration& operator=(const duration&) = default;
27
 
28
+ // [time.duration.observer], observer
29
  constexpr rep count() const;
30
 
31
+ // [time.duration.arithmetic], arithmetic
32
+ constexpr common_type_t<duration> operator+() const;
33
+ constexpr common_type_t<duration> operator-() const;
34
+ constexpr duration& operator++();
35
+ constexpr duration operator++(int);
36
+ constexpr duration& operator--();
37
+ constexpr duration operator--(int);
38
 
39
+ constexpr duration& operator+=(const duration& d);
40
+ constexpr duration& operator-=(const duration& d);
41
 
42
+ constexpr duration& operator*=(const rep& rhs);
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.
68
 
69
+ [*Example 1*:
 
 
 
 
 
 
70
 
71
  ``` cpp
72
  duration<long, ratio<60>> d0; // holds a count of minutes using a long
73
  duration<long long, milli> d1; // holds a count of milliseconds using a long long
74
  duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
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*:
94
 
95
  ``` cpp
96
  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
118
+ converting between integral-based `duration` types. Such a construction
119
+ could easily lead to confusion about the value of the
120
+ `duration`. — *end note*]
121
+
122
+ [*Example 2*:
123
 
124
  ``` cpp
125
  duration<int, milli> ms(3);
126
  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>
 
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
 
150
+ *Returns:* `common_type_t<duration>(*this)`.
151
 
152
  ``` cpp
153
+ constexpr common_type_t<duration> operator-() const;
154
  ```
155
 
156
+ *Returns:* `common_type_t<duration>(-rep_)`.
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
 
 
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);
263
  ```
264
 
265
+ *Returns:* `CD(CD(lhs).count() + CD(rhs).count())`.
266
 
267
  ``` cpp
268
  template <class Rep1, class Period1, class Rep2, class Period2>
269
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
270
  operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
271
  ```
272
 
273
+ *Returns:* `CD(CD(lhs).count() - CD(rhs).count())`.
274
 
275
  ``` cpp
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);
 
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);
 
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>
331
  constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, 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
 
343
  ``` cpp
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>
 
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
  ```
 
420
  ``` cpp
421
  ToDuration(static_cast<typename ToDuration::rep>(
422
  static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
423
  ```
424
 
425
+ [*Note 1*: This function does not use any implicit conversions; all
426
  conversions are done with `static_cast`. It avoids multiplications and
427
  divisions when it is known at compile time that one or more arguments
428
  is 1. Intermediate computations are carried out in the widest
429
  representation and only converted to the destination representation at
430
+ the final step. — *end note*]
431
+
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
+
485
  The following code shows some duration literals.
486
 
487
  ``` cpp
488
  using namespace std::chrono_literals;
489
  auto constexpr aday=24h;
490
  auto constexpr lesson=45min;
491
  auto constexpr halfanhour=0.5h;
492
  ```
493
 
494
+ — *end example*]
495
+
496
  ``` cpp
497
  constexpr chrono::hours operator""h(unsigned long long hours);
498
  constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
499
  ```
500
 
 
506
  ```
507
 
508
  *Returns:* A `duration` literal representing `minutes` minutes.
509
 
510
  ``` cpp
511
+ constexpr chrono::seconds \itcorr operator""s(unsigned long long sec);
512
  constexpr chrono::duration<unspecified> operator""s(long double sec);
513
  ```
514
 
515
  *Returns:* A `duration` literal representing `sec` seconds.
516
 
517
+ [*Note 1*: The same suffix `s` is used for `basic_string` but there is
518
+ no conflict, since duration suffixes apply to numbers and string literal
519
+ suffixes apply to character array literals. — *end note*]
520
 
521
  ``` cpp
522
  constexpr chrono::milliseconds operator""ms(unsigned long long msec);
523
  constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
524
  ```
 
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
+