tmp/tmpv4fhy5x_/{from.md → to.md}
RENAMED
|
@@ -63,10 +63,15 @@ is ill-formed.
|
|
| 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 |
``` cpp
|
| 69 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
| 70 |
duration<long long, milli> d1; // holds a count of milliseconds using a long long
|
| 71 |
duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
|
| 72 |
// (30 Hz) using a double
|
|
@@ -98,11 +103,12 @@ duration<int, milli> d(3.5); // error
|
|
| 98 |
template <class Rep2, class Period2>
|
| 99 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 100 |
```
|
| 101 |
|
| 102 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 103 |
-
unless
|
|
|
|
| 104 |
`ratio_divide<Period2, period>::den` is `1` and
|
| 105 |
`treat_as_floating_point<Rep2>::value` is `false`. This requirement
|
| 106 |
prevents implicit truncation error when converting between
|
| 107 |
integral-based `duration` types. Such a construction could easily lead
|
| 108 |
to confusion about the value of the `duration`.
|
|
@@ -236,53 +242,53 @@ static constexpr duration max();
|
|
| 236 |
*Returns:* `duration(duration_values<rep>::max())`.
|
| 237 |
|
| 238 |
#### `duration` non-member arithmetic <a id="time.duration.nonmember">[[time.duration.nonmember]]</a>
|
| 239 |
|
| 240 |
In the function descriptions that follow, `CD` represents the return
|
| 241 |
-
type of the function. `CR(A,B)` represents `
|
| 242 |
|
| 243 |
``` cpp
|
| 244 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 245 |
-
constexpr
|
| 246 |
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 247 |
```
|
| 248 |
|
| 249 |
*Returns:* CD(CD(lhs).count() + CD(rhs).count()).
|
| 250 |
|
| 251 |
``` cpp
|
| 252 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 253 |
-
constexpr
|
| 254 |
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 255 |
```
|
| 256 |
|
| 257 |
*Returns:* CD(CD(lhs).count() - CD(rhs).count()).
|
| 258 |
|
| 259 |
``` cpp
|
| 260 |
template <class Rep1, class Period, class Rep2>
|
| 261 |
-
constexpr duration<
|
| 262 |
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 263 |
```
|
| 264 |
|
| 265 |
*Remarks:* This operator shall not participate in overload resolution
|
| 266 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 267 |
|
| 268 |
*Returns:* CD(CD(d).count() \* s).
|
| 269 |
|
| 270 |
``` cpp
|
| 271 |
template <class Rep1, class Rep2, class Period>
|
| 272 |
-
constexpr duration<
|
| 273 |
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
| 274 |
```
|
| 275 |
|
| 276 |
*Remarks:* This operator shall not participate in overload resolution
|
| 277 |
unless `Rep1` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 278 |
|
| 279 |
*Returns:* `d * s`.
|
| 280 |
|
| 281 |
``` cpp
|
| 282 |
template <class Rep1, class Period, class Rep2>
|
| 283 |
-
constexpr duration<
|
| 284 |
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 285 |
```
|
| 286 |
|
| 287 |
*Remarks:* This operator shall not participate in overload resolution
|
| 288 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
|
@@ -290,19 +296,19 @@ is not an instantiation of `duration`.
|
|
| 290 |
|
| 291 |
*Returns:* CD(CD(d).count() / s).
|
| 292 |
|
| 293 |
``` cpp
|
| 294 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 295 |
-
constexpr
|
| 296 |
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 297 |
```
|
| 298 |
|
| 299 |
*Returns:* `CD(lhs).count() / CD(rhs).count()`.
|
| 300 |
|
| 301 |
``` cpp
|
| 302 |
template <class Rep1, class Period, class Rep2>
|
| 303 |
-
constexpr duration<
|
| 304 |
operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 305 |
```
|
| 306 |
|
| 307 |
*Remarks:* This operator shall not participate in overload resolution
|
| 308 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
|
@@ -310,20 +316,20 @@ is not an instantiation of `duration`.
|
|
| 310 |
|
| 311 |
*Returns:* CD(CD(d).count() % s).
|
| 312 |
|
| 313 |
``` cpp
|
| 314 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 315 |
-
constexpr
|
| 316 |
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 317 |
```
|
| 318 |
|
| 319 |
*Returns:* CD(CD(lhs).count() % CD(rhs).count()).
|
| 320 |
|
| 321 |
#### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
|
| 322 |
|
| 323 |
In the function descriptions that follow, `CT` represents
|
| 324 |
-
`
|
| 325 |
arguments to the function.
|
| 326 |
|
| 327 |
``` cpp
|
| 328 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 329 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
@@ -405,5 +411,76 @@ conversions are done with `static_cast`. It avoids multiplications and
|
|
| 405 |
divisions when it is known at compile time that one or more arguments
|
| 406 |
is 1. Intermediate computations are carried out in the widest
|
| 407 |
representation and only converted to the destination representation at
|
| 408 |
the final step.
|
| 409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 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`.
|
|
|
|
| 242 |
*Returns:* `duration(duration_values<rep>::max())`.
|
| 243 |
|
| 244 |
#### `duration` non-member arithmetic <a id="time.duration.nonmember">[[time.duration.nonmember]]</a>
|
| 245 |
|
| 246 |
In the function descriptions that follow, `CD` represents the return
|
| 247 |
+
type of the function. `CR(A,B)` represents `common_type_t<A, B>`.
|
| 248 |
|
| 249 |
``` cpp
|
| 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);
|
| 280 |
```
|
| 281 |
|
| 282 |
*Remarks:* This operator shall not participate in overload resolution
|
| 283 |
unless `Rep1` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 284 |
|
| 285 |
*Returns:* `d * s`.
|
| 286 |
|
| 287 |
``` cpp
|
| 288 |
template <class Rep1, class Period, class Rep2>
|
| 289 |
+
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 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`
|
|
|
|
| 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);
|
| 303 |
```
|
| 304 |
|
| 305 |
*Returns:* `CD(lhs).count() / CD(rhs).count()`.
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
template <class Rep1, class Period, class Rep2>
|
| 309 |
+
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 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`
|
|
|
|
| 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);
|
|
|
|
| 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 |
+
|
| 446 |
+
*Returns:* A `duration` literal representing `hours` hours.
|
| 447 |
+
|
| 448 |
+
``` cpp
|
| 449 |
+
constexpr chrono::minutes operator "" min(unsigned long long minutes);
|
| 450 |
+
constexpr chrono::duration<unspecified, ratio<60,1>> operator "" min(long double minutes);
|
| 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 |
+
```
|
| 470 |
+
|
| 471 |
+
*Returns:* A `duration` literal representing `msec` milliseconds.
|
| 472 |
+
|
| 473 |
+
``` cpp
|
| 474 |
+
constexpr chrono::microseconds operator "" us(unsigned long long usec);
|
| 475 |
+
constexpr chrono::duration<unspecified, micro> operator "" us(long double usec);
|
| 476 |
+
```
|
| 477 |
+
|
| 478 |
+
*Returns:* A `duration` literal representing `usec` microseconds.
|
| 479 |
+
|
| 480 |
+
``` cpp
|
| 481 |
+
constexpr chrono::nanoseconds operator "" ns(unsigned long long nsec);
|
| 482 |
+
constexpr chrono::duration<unspecified, nano> operator "" ns(long double nsec);
|
| 483 |
+
```
|
| 484 |
+
|
| 485 |
+
*Returns:* A `duration` literal representing `nsec` nanoseconds.
|
| 486 |
+
|