- tmp/tmpax2l32mp/{from.md → to.md} +383 -210
tmp/tmpax2l32mp/{from.md → to.md}
RENAMED
|
@@ -1,47 +1,50 @@
|
|
| 1 |
## Time utilities <a id="time">[[time]]</a>
|
| 2 |
|
| 3 |
### In general <a id="time.general">[[time.general]]</a>
|
| 4 |
|
| 5 |
This subclause describes the chrono library ([[time.syn]]) and various
|
| 6 |
-
C functions ([[
|
| 7 |
utilities.
|
| 8 |
|
| 9 |
### Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
namespace std {
|
| 13 |
namespace chrono {
|
| 14 |
-
|
| 15 |
// [time.duration], class template duration
|
| 16 |
template <class Rep, class Period = ratio<1>> class duration;
|
| 17 |
|
| 18 |
// [time.point], class template time_point
|
| 19 |
template <class Clock, class Duration = typename Clock::duration> class time_point;
|
|
|
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
// [time.traits.specializations] common_type specializations
|
| 24 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 25 |
-
|
|
|
|
| 26 |
|
| 27 |
template <class Clock, class Duration1, class Duration2>
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
namespace chrono {
|
| 31 |
-
|
| 32 |
// [time.traits], customization traits
|
| 33 |
template <class Rep> struct treat_as_floating_point;
|
| 34 |
template <class Rep> struct duration_values;
|
|
|
|
|
|
|
| 35 |
|
| 36 |
// [time.duration.nonmember], duration arithmetic
|
| 37 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 38 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 39 |
-
|
|
|
|
| 40 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 41 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 42 |
-
|
|
|
|
| 43 |
template <class Rep1, class Period, class Rep2>
|
| 44 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 45 |
constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 46 |
template <class Rep1, class Rep2, class Period>
|
| 47 |
duration<common_type_t<Rep1, Rep2>, Period>
|
|
@@ -49,17 +52,19 @@ template <class Rep1, class Rep2, class Period>
|
|
| 49 |
template <class Rep1, class Period, class Rep2>
|
| 50 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 51 |
constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 52 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 53 |
common_type_t<Rep1, Rep2>
|
| 54 |
-
|
|
|
|
| 55 |
template <class Rep1, class Period, class Rep2>
|
| 56 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 57 |
constexpr operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 58 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 59 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 60 |
-
|
|
|
|
| 61 |
|
| 62 |
// [time.duration.comparisons], duration comparisons
|
| 63 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 64 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 65 |
const duration<Rep2, Period2>& rhs);
|
|
@@ -80,34 +85,44 @@ template <class Rep1, class Period1, class Rep2, class Period2>
|
|
| 80 |
const duration<Rep2, Period2>& rhs);
|
| 81 |
|
| 82 |
// [time.duration.cast], duration_cast
|
| 83 |
template <class ToDuration, class Rep, class Period>
|
| 84 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
// convenience typedefs
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
// [time.point.nonmember], time_point arithmetic
|
| 95 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 96 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 97 |
-
|
|
|
|
| 98 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 99 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 100 |
-
|
|
|
|
| 101 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 102 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 103 |
-
|
|
|
|
| 104 |
template <class Clock, class Duration1, class Duration2>
|
| 105 |
constexpr common_type_t<Duration1, Duration2>
|
| 106 |
-
|
|
|
|
| 107 |
|
| 108 |
-
// [time.point.comparisons] time_point comparisons
|
| 109 |
template <class Clock, class Duration1, class Duration2>
|
| 110 |
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 111 |
const time_point<Clock, Duration2>& rhs);
|
| 112 |
template <class Clock, class Duration1, class Duration2>
|
| 113 |
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
@@ -127,22 +142,33 @@ template <class Clock, class Duration1, class Duration2>
|
|
| 127 |
|
| 128 |
// [time.point.cast], time_point_cast
|
| 129 |
template <class ToDuration, class Clock, class Duration>
|
| 130 |
constexpr time_point<Clock, ToDuration>
|
| 131 |
time_point_cast(const time_point<Clock, Duration>& t);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
|
| 133 |
// [time.clock], clocks
|
| 134 |
class system_clock;
|
| 135 |
class steady_clock;
|
| 136 |
class high_resolution_clock;
|
| 137 |
-
|
| 138 |
-
} // namespace chrono
|
| 139 |
|
| 140 |
inline namespace literals {
|
| 141 |
inline namespace chrono_literals {
|
| 142 |
-
|
| 143 |
-
// ~[time.duration.literals], suffixes for duration literals
|
| 144 |
constexpr chrono::hours operator""h(unsigned long long);
|
| 145 |
constexpr chrono::duration<unspecified, ratio<3600,1>> operator""h(long double);
|
| 146 |
constexpr chrono::minutes operator""min(unsigned long long);
|
| 147 |
constexpr chrono::duration<unspecified, ratio<60,1>> operator""min(long double);
|
| 148 |
constexpr chrono::seconds operator""s(unsigned long long);
|
|
@@ -151,21 +177,17 @@ constexpr chrono::milliseconds operator "" ms(unsigned
|
|
| 151 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double);
|
| 152 |
constexpr chrono::microseconds operator""us(unsigned long long);
|
| 153 |
constexpr chrono::duration<unspecified, micro> operator""us(long double);
|
| 154 |
constexpr chrono::nanoseconds operator""ns(unsigned long long);
|
| 155 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double);
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
} // namespace literals
|
| 159 |
|
| 160 |
namespace chrono {
|
| 161 |
-
|
| 162 |
using namespace literals::chrono_literals;
|
| 163 |
-
|
| 164 |
-
}
|
| 165 |
-
|
| 166 |
-
} // namespace std
|
| 167 |
```
|
| 168 |
|
| 169 |
### Clock requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 170 |
|
| 171 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
@@ -174,29 +196,32 @@ clock’s `time_point` is referred to as the clock’s *epoch*. A clock
|
|
| 174 |
shall meet the requirements in Table [[tab:time.clock]].
|
| 175 |
|
| 176 |
In Table [[tab:time.clock]] `C1` and `C2` denote clock types. `t1` and
|
| 177 |
`t2` are values returned by `C1::now()` where the call returning `t1`
|
| 178 |
happens before ([[intro.multithread]]) the call returning `t2` and both
|
| 179 |
-
of these calls occur before `C1::time_point::max()`.
|
| 180 |
-
not wrap around between `t1` and `t2`.
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
A type `TC` meets the `TrivialClock` requirements if:
|
| 187 |
|
| 188 |
- `TC` satisfies the `Clock` requirements ([[time.clock.req]]),
|
| 189 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the
|
| 190 |
-
requirements of `EqualityComparable` (Table
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
| 195 |
and the requirements of numeric types ([[numeric.requirements]]).
|
| 196 |
-
|
| 197 |
-
throw exceptions.
|
| 198 |
- lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point`
|
| 199 |
are swappable ([[swappable.requirements]]),
|
| 200 |
- the function `TC::now()` does not throw exceptions, and
|
| 201 |
- the type `TC::time_point::clock` meets the `TrivialClock`
|
| 202 |
requirements, recursively.
|
|
@@ -210,19 +235,21 @@ template <class Rep> struct treat_as_floating_point
|
|
| 210 |
: is_floating_point<Rep> { };
|
| 211 |
```
|
| 212 |
|
| 213 |
The `duration` template uses the `treat_as_floating_point` trait to help
|
| 214 |
determine if a `duration` object can be converted to another `duration`
|
| 215 |
-
with a different tick `period`. If `
|
| 216 |
-
|
| 217 |
Otherwise, the implicit convertibility depends on the tick `period`s of
|
| 218 |
-
the `duration`s.
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
|
|
|
| 224 |
|
| 225 |
#### `duration_values` <a id="time.traits.duration_values">[[time.traits.duration_values]]</a>
|
| 226 |
|
| 227 |
``` cpp
|
| 228 |
template <class Rep>
|
|
@@ -243,57 +270,62 @@ that case, the author of that class type should specialize
|
|
| 243 |
|
| 244 |
``` cpp
|
| 245 |
static constexpr Rep zero();
|
| 246 |
```
|
| 247 |
|
| 248 |
-
*Returns:* `Rep(0)`.
|
| 249 |
-
`Rep()` may have some other meaning, such as an uninitialized value.
|
| 250 |
|
| 251 |
-
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
``` cpp
|
| 254 |
static constexpr Rep min();
|
| 255 |
```
|
| 256 |
|
| 257 |
*Returns:* `numeric_limits<Rep>::lowest()`.
|
| 258 |
|
| 259 |
-
The value returned shall compare less than or equal to
|
|
|
|
| 260 |
|
| 261 |
``` cpp
|
| 262 |
static constexpr Rep max();
|
| 263 |
```
|
| 264 |
|
| 265 |
*Returns:* `numeric_limits<Rep>::max()`.
|
| 266 |
|
| 267 |
-
The value returned shall compare greater than `zero()`.
|
| 268 |
|
| 269 |
#### Specializations of `common_type` <a id="time.traits.specializations">[[time.traits.specializations]]</a>
|
| 270 |
|
| 271 |
``` cpp
|
| 272 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 273 |
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> {
|
| 274 |
-
|
| 275 |
};
|
| 276 |
```
|
| 277 |
|
| 278 |
The `period` of the `duration` indicated by this specialization of
|
| 279 |
`common_type` shall be the greatest common divisor of `Period1` and
|
| 280 |
-
`Period2`.
|
|
|
|
|
|
|
| 281 |
common divisor of `Period1::num` and `Period2::num` and the least common
|
| 282 |
-
multiple of `Period1::den` and `Period2::den`.
|
| 283 |
|
| 284 |
-
The `typedef` name `type` is a synonym for the `duration`
|
| 285 |
-
largest tick `period` possible where both `duration` arguments
|
| 286 |
-
convert to it without requiring a division operation. The
|
| 287 |
-
of this type is intended to be able to hold any value
|
| 288 |
-
this conversion with no truncation error, although
|
| 289 |
-
durations may have round-off errors.
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
template <class Clock, class Duration1, class Duration2>
|
| 293 |
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> {
|
| 294 |
-
|
| 295 |
};
|
| 296 |
```
|
| 297 |
|
| 298 |
The common type of two `time_point` types is a `time_point` with the
|
| 299 |
same clock as the two types and the common type of their two
|
|
@@ -309,119 +341,129 @@ as a rational constant using the template `ratio`.
|
|
| 309 |
|
| 310 |
``` cpp
|
| 311 |
template <class Rep, class Period = ratio<1>>
|
| 312 |
class duration {
|
| 313 |
public:
|
| 314 |
-
|
| 315 |
-
|
| 316 |
private:
|
| 317 |
rep rep_; // exposition only
|
| 318 |
public:
|
| 319 |
-
// [time.duration.cons], construct/copy/destroy
|
| 320 |
constexpr duration() = default;
|
| 321 |
template <class Rep2>
|
| 322 |
constexpr explicit duration(const Rep2& r);
|
| 323 |
template <class Rep2, class Period2>
|
| 324 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 325 |
~duration() = default;
|
| 326 |
duration(const duration&) = default;
|
| 327 |
duration& operator=(const duration&) = default;
|
| 328 |
|
| 329 |
-
// [time.duration.observer], observer
|
| 330 |
constexpr rep count() const;
|
| 331 |
|
| 332 |
-
// [time.duration.arithmetic], arithmetic
|
| 333 |
-
constexpr duration
|
| 334 |
-
constexpr duration
|
| 335 |
-
duration& operator++();
|
| 336 |
-
duration operator++(int);
|
| 337 |
-
duration& operator--();
|
| 338 |
-
duration operator--(int);
|
| 339 |
|
| 340 |
-
duration& operator+=(const duration& d);
|
| 341 |
-
duration& operator-=(const duration& d);
|
| 342 |
|
| 343 |
-
duration& operator*=(const rep& rhs);
|
| 344 |
-
duration& operator/=(const rep& rhs);
|
| 345 |
-
duration& operator%=(const rep& rhs);
|
| 346 |
-
duration& operator%=(const duration& rhs);
|
| 347 |
|
| 348 |
-
// [time.duration.special], special values
|
| 349 |
static constexpr duration zero();
|
| 350 |
static constexpr duration min();
|
| 351 |
static constexpr duration max();
|
| 352 |
};
|
| 353 |
```
|
| 354 |
|
| 355 |
-
|
| 356 |
-
|
|
|
|
| 357 |
|
| 358 |
-
|
| 359 |
-
|
| 360 |
|
| 361 |
-
|
| 362 |
-
|
| 363 |
|
| 364 |
-
|
|
|
|
|
|
|
|
|
|
| 365 |
|
| 366 |
-
*
|
| 367 |
-
those thrown by the indicated operations on their representations.
|
| 368 |
-
|
| 369 |
-
*Remarks:* The defaulted copy constructor of duration shall be a
|
| 370 |
-
`constexpr` function if and only if the required initialization of the
|
| 371 |
-
member `rep_` for copy and move, respectively, would satisfy the
|
| 372 |
-
requirements for a `constexpr` function.
|
| 373 |
|
| 374 |
``` cpp
|
| 375 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
| 376 |
duration<long long, milli> d1; // holds a count of milliseconds using a long long
|
| 377 |
duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
|
| 378 |
// (30 Hz) using a double
|
| 379 |
```
|
| 380 |
|
|
|
|
|
|
|
| 381 |
#### `duration` constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
|
| 382 |
|
| 383 |
``` cpp
|
| 384 |
template <class Rep2>
|
| 385 |
constexpr explicit duration(const Rep2& r);
|
| 386 |
```
|
| 387 |
|
| 388 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 389 |
unless `Rep2` is implicitly convertible to `rep` and
|
| 390 |
|
| 391 |
-
- `
|
| 392 |
-
- `
|
|
|
|
|
|
|
| 393 |
|
| 394 |
``` cpp
|
| 395 |
duration<int, milli> d(3); // OK
|
| 396 |
duration<int, milli> d(3.5); // error
|
| 397 |
```
|
| 398 |
|
|
|
|
|
|
|
| 399 |
*Effects:* Constructs an object of type `duration`.
|
| 400 |
|
| 401 |
-
`count() == static_cast<rep>(r)`.
|
| 402 |
|
| 403 |
``` cpp
|
| 404 |
template <class Rep2, class Period2>
|
| 405 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 406 |
```
|
| 407 |
|
| 408 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 409 |
unless no overflow is induced in the conversion and
|
| 410 |
-
`
|
| 411 |
`ratio_divide<Period2, period>::den` is `1` and
|
| 412 |
-
`
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 416 |
|
| 417 |
``` cpp
|
| 418 |
duration<int, milli> ms(3);
|
| 419 |
duration<int, micro> us = ms; // OK
|
| 420 |
duration<int, milli> ms2 = us; // error
|
| 421 |
```
|
| 422 |
|
|
|
|
|
|
|
| 423 |
*Effects:* Constructs an object of type `duration`, constructing `rep_`
|
| 424 |
from
|
| 425 |
`duration_cast<duration>(d).count()`.
|
| 426 |
|
| 427 |
#### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
|
|
@@ -433,94 +475,94 @@ constexpr rep count() const;
|
|
| 433 |
*Returns:* `rep_`.
|
| 434 |
|
| 435 |
#### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
|
| 436 |
|
| 437 |
``` cpp
|
| 438 |
-
constexpr duration operator+() const;
|
| 439 |
```
|
| 440 |
|
| 441 |
-
*Returns:* `*this`.
|
| 442 |
|
| 443 |
``` cpp
|
| 444 |
-
constexpr duration operator-() const;
|
| 445 |
```
|
| 446 |
|
| 447 |
-
*Returns:* `duration(-rep_)
|
| 448 |
|
| 449 |
``` cpp
|
| 450 |
-
duration& operator++();
|
| 451 |
```
|
| 452 |
|
| 453 |
-
*Effects:* `++rep_`.
|
| 454 |
|
| 455 |
*Returns:* `*this`.
|
| 456 |
|
| 457 |
``` cpp
|
| 458 |
-
duration operator++(int);
|
| 459 |
```
|
| 460 |
|
| 461 |
-
*Returns:* `duration(rep_++)
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
-
duration& operator--();
|
| 465 |
```
|
| 466 |
|
| 467 |
-
*Effects:* `
|
| 468 |
|
| 469 |
*Returns:* `*this`.
|
| 470 |
|
| 471 |
``` cpp
|
| 472 |
-
duration operator--(int);
|
| 473 |
```
|
| 474 |
|
| 475 |
-
*Returns:* `duration(rep_--)
|
| 476 |
|
| 477 |
``` cpp
|
| 478 |
-
duration& operator+=(const duration& d);
|
| 479 |
```
|
| 480 |
|
| 481 |
-
*Effects:* `rep_ += d.count()`
|
| 482 |
|
| 483 |
*Returns:* `*this`.
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
-
duration& operator-=(const duration& d);
|
| 487 |
```
|
| 488 |
|
| 489 |
-
*Effects:* `rep_ -= d.count()`
|
| 490 |
|
| 491 |
*Returns:* `*this`.
|
| 492 |
|
| 493 |
``` cpp
|
| 494 |
-
duration& operator*=(const rep& rhs);
|
| 495 |
```
|
| 496 |
|
| 497 |
-
*Effects:* `rep_ *= rhs`
|
| 498 |
|
| 499 |
*Returns:* `*this`.
|
| 500 |
|
| 501 |
``` cpp
|
| 502 |
-
duration& operator/=(const rep& rhs);
|
| 503 |
```
|
| 504 |
|
| 505 |
-
*Effects:* `rep_ /= rhs`
|
| 506 |
|
| 507 |
*Returns:* `*this`.
|
| 508 |
|
| 509 |
``` cpp
|
| 510 |
-
duration& operator%=(const rep& rhs);
|
| 511 |
```
|
| 512 |
|
| 513 |
-
*Effects:* `rep_ %= rhs`
|
| 514 |
|
| 515 |
*Returns:* `*this`.
|
| 516 |
|
| 517 |
``` cpp
|
| 518 |
-
duration& operator%=(const duration& rhs);
|
| 519 |
```
|
| 520 |
|
| 521 |
-
*Effects:* `rep_ %= rhs.count()`
|
| 522 |
|
| 523 |
*Returns:* `*this`.
|
| 524 |
|
| 525 |
#### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
|
| 526 |
|
|
@@ -551,30 +593,30 @@ type of the function. `CR(A,B)` represents `common_type_t<A, B>`.
|
|
| 551 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 552 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 553 |
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 554 |
```
|
| 555 |
|
| 556 |
-
*Returns:* CD(CD(lhs).count() + CD(rhs).count()).
|
| 557 |
|
| 558 |
``` cpp
|
| 559 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 560 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 561 |
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 562 |
```
|
| 563 |
|
| 564 |
-
*Returns:* CD(CD(lhs).count() - CD(rhs).count()).
|
| 565 |
|
| 566 |
``` cpp
|
| 567 |
template <class Rep1, class Period, class Rep2>
|
| 568 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 569 |
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 570 |
```
|
| 571 |
|
| 572 |
*Remarks:* This operator shall not participate in overload resolution
|
| 573 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 574 |
|
| 575 |
-
*Returns:* CD(CD(d).count()
|
| 576 |
|
| 577 |
``` cpp
|
| 578 |
template <class Rep1, class Rep2, class Period>
|
| 579 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 580 |
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
|
@@ -591,13 +633,13 @@ template <class Rep1, class Period, class Rep2>
|
|
| 591 |
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 592 |
```
|
| 593 |
|
| 594 |
*Remarks:* This operator shall not participate in overload resolution
|
| 595 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 596 |
-
is not
|
| 597 |
|
| 598 |
-
*Returns:* CD(CD(d).count() / s).
|
| 599 |
|
| 600 |
``` cpp
|
| 601 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 602 |
constexpr common_type_t<Rep1, Rep2>
|
| 603 |
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
@@ -611,66 +653,72 @@ template <class Rep1, class Period, class Rep2>
|
|
| 611 |
operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 612 |
```
|
| 613 |
|
| 614 |
*Remarks:* This operator shall not participate in overload resolution
|
| 615 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 616 |
-
is not
|
| 617 |
|
| 618 |
-
*Returns:* CD(CD(d).count() % s).
|
| 619 |
|
| 620 |
``` cpp
|
| 621 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 622 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 623 |
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 624 |
```
|
| 625 |
|
| 626 |
-
*Returns:* CD(CD(lhs).count() % CD(rhs).count()).
|
| 627 |
|
| 628 |
#### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
|
| 629 |
|
| 630 |
In the function descriptions that follow, `CT` represents
|
| 631 |
`common_type_t<A, B>`, where `A` and `B` are the types of the two
|
| 632 |
arguments to the function.
|
| 633 |
|
| 634 |
``` cpp
|
| 635 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 636 |
-
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 637 |
```
|
| 638 |
|
| 639 |
-
*Returns:* `CT(lhs).count() == CT(rhs).count()`.
|
| 640 |
|
| 641 |
``` cpp
|
| 642 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 643 |
-
constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 644 |
```
|
| 645 |
|
| 646 |
*Returns:* `!(lhs == rhs)`.
|
| 647 |
|
| 648 |
``` cpp
|
| 649 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 650 |
-
constexpr bool operator<(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 651 |
```
|
| 652 |
|
| 653 |
-
*Returns:* `CT(lhs).count() < CT(rhs).count()`.
|
| 654 |
|
| 655 |
``` cpp
|
| 656 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 657 |
-
constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 658 |
```
|
| 659 |
|
| 660 |
*Returns:* `!(rhs < lhs)`.
|
| 661 |
|
| 662 |
``` cpp
|
| 663 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 664 |
-
constexpr bool operator>(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 665 |
```
|
| 666 |
|
| 667 |
*Returns:* `rhs < lhs`.
|
| 668 |
|
| 669 |
``` cpp
|
| 670 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 671 |
-
constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
|
|
|
|
| 672 |
```
|
| 673 |
|
| 674 |
*Returns:* `!(lhs < rhs)`.
|
| 675 |
|
| 676 |
#### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
|
|
@@ -679,15 +727,15 @@ template <class Rep1, class Period1, class Rep2, class Period2>
|
|
| 679 |
template <class ToDuration, class Rep, class Period>
|
| 680 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 681 |
```
|
| 682 |
|
| 683 |
*Remarks:* This function shall not participate in overload resolution
|
| 684 |
-
unless `ToDuration` is
|
| 685 |
|
| 686 |
*Returns:* Let `CF` be
|
| 687 |
`ratio_divide<Period, typename ToDuration::period>`, and `CR` be
|
| 688 |
-
`common_type<` `typename ToDuration::rep, Rep, intmax_t>::type
|
| 689 |
|
| 690 |
- If `CF::num == 1` and `CF::den == 1`, returns
|
| 691 |
``` cpp
|
| 692 |
ToDuration(static_cast<typename ToDuration::rep>(d.count()))
|
| 693 |
```
|
|
@@ -705,42 +753,81 @@ unless `ToDuration` is an instantiation of `duration`.
|
|
| 705 |
``` cpp
|
| 706 |
ToDuration(static_cast<typename ToDuration::rep>(
|
| 707 |
static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
|
| 708 |
```
|
| 709 |
|
| 710 |
-
*
|
| 711 |
conversions are done with `static_cast`. It avoids multiplications and
|
| 712 |
divisions when it is known at compile time that one or more arguments
|
| 713 |
is 1. Intermediate computations are carried out in the widest
|
| 714 |
representation and only converted to the destination representation at
|
| 715 |
-
the final step.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
|
| 717 |
#### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
|
| 718 |
|
| 719 |
This section describes literal suffixes for constructing duration
|
| 720 |
literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
|
| 721 |
values of the corresponding types `hours`, `minutes`, `seconds`,
|
| 722 |
`milliseconds`, `microseconds`, and `nanoseconds` respectively if they
|
| 723 |
are applied to integral literals.
|
| 724 |
|
| 725 |
-
If any of these suffixes are applied to a floating
|
| 726 |
-
result is a `chrono::duration` literal with an unspecified
|
| 727 |
-
point representation.
|
| 728 |
|
| 729 |
If any of these suffixes are applied to an integer literal and the
|
| 730 |
resulting `chrono::duration` value cannot be represented in the result
|
| 731 |
type because of overflow, the program is ill-formed.
|
| 732 |
|
|
|
|
|
|
|
| 733 |
The following code shows some duration literals.
|
| 734 |
|
| 735 |
``` cpp
|
| 736 |
using namespace std::chrono_literals;
|
| 737 |
auto constexpr aday=24h;
|
| 738 |
auto constexpr lesson=45min;
|
| 739 |
auto constexpr halfanhour=0.5h;
|
| 740 |
```
|
| 741 |
|
|
|
|
|
|
|
| 742 |
``` cpp
|
| 743 |
constexpr chrono::hours operator""h(unsigned long long hours);
|
| 744 |
constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
|
| 745 |
```
|
| 746 |
|
|
@@ -752,19 +839,19 @@ constexpr chrono::duration<unspecified, ratio<60,1>> operator "" min(long double
|
|
| 752 |
```
|
| 753 |
|
| 754 |
*Returns:* A `duration` literal representing `minutes` minutes.
|
| 755 |
|
| 756 |
``` cpp
|
| 757 |
-
constexpr chrono::seconds
|
| 758 |
constexpr chrono::duration<unspecified> operator""s(long double sec);
|
| 759 |
```
|
| 760 |
|
| 761 |
*Returns:* A `duration` literal representing `sec` seconds.
|
| 762 |
|
| 763 |
-
The same suffix `s` is used for `basic_string` but there is
|
| 764 |
-
since duration suffixes apply to numbers and string literal
|
| 765 |
-
apply to character array literals.
|
| 766 |
|
| 767 |
``` cpp
|
| 768 |
constexpr chrono::milliseconds operator""ms(unsigned long long msec);
|
| 769 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
|
| 770 |
```
|
|
@@ -783,44 +870,56 @@ constexpr chrono::nanoseconds operator "" ns(unsigned long long
|
|
| 783 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
|
| 784 |
```
|
| 785 |
|
| 786 |
*Returns:* A `duration` literal representing `nsec` nanoseconds.
|
| 787 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 788 |
### Class template `time_point` <a id="time.point">[[time.point]]</a>
|
| 789 |
|
| 790 |
``` cpp
|
| 791 |
template <class Clock, class Duration = typename Clock::duration>
|
| 792 |
class time_point {
|
| 793 |
public:
|
| 794 |
-
|
| 795 |
-
|
| 796 |
-
|
| 797 |
-
|
| 798 |
private:
|
| 799 |
duration d_; // exposition only
|
| 800 |
|
| 801 |
public:
|
| 802 |
-
// [time.point.cons], construct
|
| 803 |
constexpr time_point(); // has value epoch
|
| 804 |
constexpr explicit time_point(const duration& d); // same as time_point() + d
|
| 805 |
template <class Duration2>
|
| 806 |
constexpr time_point(const time_point<clock, Duration2>& t);
|
| 807 |
|
| 808 |
-
// [time.point.observer], observer
|
| 809 |
constexpr duration time_since_epoch() const;
|
| 810 |
|
| 811 |
-
// [time.point.arithmetic], arithmetic
|
| 812 |
-
time_point& operator+=(const duration& d);
|
| 813 |
-
time_point& operator-=(const duration& d);
|
| 814 |
|
| 815 |
-
// [time.point.special], special values
|
| 816 |
static constexpr time_point min();
|
| 817 |
static constexpr time_point max();
|
| 818 |
};
|
| 819 |
```
|
| 820 |
|
| 821 |
-
`Clock` shall meet the Clock requirements ([[time.clock]]).
|
| 822 |
|
| 823 |
If `Duration` is not an instance of `duration`, the program is
|
| 824 |
ill-formed.
|
| 825 |
|
| 826 |
#### `time_point` constructors <a id="time.point.cons">[[time.point.cons]]</a>
|
|
@@ -860,22 +959,22 @@ constexpr duration time_since_epoch() const;
|
|
| 860 |
*Returns:* `d_`.
|
| 861 |
|
| 862 |
#### `time_point` arithmetic <a id="time.point.arithmetic">[[time.point.arithmetic]]</a>
|
| 863 |
|
| 864 |
``` cpp
|
| 865 |
-
time_point& operator+=(const duration& d);
|
| 866 |
```
|
| 867 |
|
| 868 |
-
*Effects:* `d_ += d`
|
| 869 |
|
| 870 |
*Returns:* `*this`.
|
| 871 |
|
| 872 |
``` cpp
|
| 873 |
-
time_point& operator-=(const duration& d);
|
| 874 |
```
|
| 875 |
|
| 876 |
-
*Effects:* `d_ -= d`
|
| 877 |
|
| 878 |
*Returns:* `*this`.
|
| 879 |
|
| 880 |
#### `time_point` special values <a id="time.point.special">[[time.point.special]]</a>
|
| 881 |
|
|
@@ -897,12 +996,12 @@ static constexpr time_point max();
|
|
| 897 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 898 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 899 |
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 900 |
```
|
| 901 |
|
| 902 |
-
*Returns:* `CT(lhs.time_since_epoch() + rhs)`, where `CT` is the
|
| 903 |
-
the return value.
|
| 904 |
|
| 905 |
``` cpp
|
| 906 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 907 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 908 |
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
@@ -914,11 +1013,12 @@ template <class Rep1, class Period1, class Clock, class Duration2>
|
|
| 914 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 915 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 916 |
operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 917 |
```
|
| 918 |
|
| 919 |
-
*Returns:* `lhs
|
|
|
|
| 920 |
|
| 921 |
``` cpp
|
| 922 |
template <class Clock, class Duration1, class Duration2>
|
| 923 |
constexpr common_type_t<Duration1, Duration2>
|
| 924 |
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
@@ -928,46 +1028,52 @@ template <class Clock, class Duration1, class Duration2>
|
|
| 928 |
|
| 929 |
#### `time_point` comparisons <a id="time.point.comparisons">[[time.point.comparisons]]</a>
|
| 930 |
|
| 931 |
``` cpp
|
| 932 |
template <class Clock, class Duration1, class Duration2>
|
| 933 |
-
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 934 |
```
|
| 935 |
|
| 936 |
*Returns:* `lhs.time_since_epoch() == rhs.time_since_epoch()`.
|
| 937 |
|
| 938 |
``` cpp
|
| 939 |
template <class Clock, class Duration1, class Duration2>
|
| 940 |
-
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 941 |
```
|
| 942 |
|
| 943 |
*Returns:* `!(lhs == rhs)`.
|
| 944 |
|
| 945 |
``` cpp
|
| 946 |
template <class Clock, class Duration1, class Duration2>
|
| 947 |
-
constexpr bool operator<(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 948 |
```
|
| 949 |
|
| 950 |
*Returns:* `lhs.time_since_epoch() < rhs.time_since_epoch()`.
|
| 951 |
|
| 952 |
``` cpp
|
| 953 |
template <class Clock, class Duration1, class Duration2>
|
| 954 |
-
constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 955 |
```
|
| 956 |
|
| 957 |
*Returns:* `!(rhs < lhs)`.
|
| 958 |
|
| 959 |
``` cpp
|
| 960 |
template <class Clock, class Duration1, class Duration2>
|
| 961 |
-
constexpr bool operator>(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 962 |
```
|
| 963 |
|
| 964 |
*Returns:* `rhs < lhs`.
|
| 965 |
|
| 966 |
``` cpp
|
| 967 |
template <class Clock, class Duration1, class Duration2>
|
| 968 |
-
constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 969 |
```
|
| 970 |
|
| 971 |
*Returns:* `!(lhs < rhs)`.
|
| 972 |
|
| 973 |
#### `time_point_cast` <a id="time.point.cast">[[time.point.cast]]</a>
|
|
@@ -977,14 +1083,54 @@ template <class ToDuration, class Clock, class Duration>
|
|
| 977 |
constexpr time_point<Clock, ToDuration>
|
| 978 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 979 |
```
|
| 980 |
|
| 981 |
*Remarks:* This function shall not participate in overload resolution
|
| 982 |
-
unless `ToDuration` is
|
| 983 |
|
| 984 |
*Returns:*
|
| 985 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 986 |
|
| 987 |
### Clocks <a id="time.clock">[[time.clock]]</a>
|
| 988 |
|
| 989 |
The types defined in this subclause shall satisfy the `TrivialClock`
|
| 990 |
requirements ([[time.clock.req]]).
|
|
@@ -995,14 +1141,14 @@ Objects of class `system_clock` represent wall clock time from the
|
|
| 995 |
system-wide realtime clock.
|
| 996 |
|
| 997 |
``` cpp
|
| 998 |
class system_clock {
|
| 999 |
public:
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
static constexpr bool is_steady = unspecified;
|
| 1005 |
|
| 1006 |
static time_point now() noexcept;
|
| 1007 |
|
| 1008 |
// Map to C API
|
|
@@ -1010,33 +1156,35 @@ public:
|
|
| 1010 |
static time_point from_time_t(time_t t) noexcept;
|
| 1011 |
};
|
| 1012 |
```
|
| 1013 |
|
| 1014 |
``` cpp
|
| 1015 |
-
|
| 1016 |
```
|
| 1017 |
|
| 1018 |
*Requires:*
|
| 1019 |
`system_clock::duration::min() < system_clock::duration::zero()` shall
|
| 1020 |
-
be `true`.
|
|
|
|
|
|
|
| 1021 |
|
| 1022 |
``` cpp
|
| 1023 |
static time_t to_time_t(const time_point& t) noexcept;
|
| 1024 |
```
|
| 1025 |
|
| 1026 |
*Returns:* A `time_t` object that represents the same point in time as
|
| 1027 |
`t` when both values are restricted to the coarser of the precisions of
|
| 1028 |
-
`time_t` and `time_point`. It is implementation
|
| 1029 |
are rounded or truncated to the required precision.
|
| 1030 |
|
| 1031 |
``` cpp
|
| 1032 |
static time_point from_time_t(time_t t) noexcept;
|
| 1033 |
```
|
| 1034 |
|
| 1035 |
*Returns:* A `time_point` object that represents the same point in time
|
| 1036 |
as `t` when both values are restricted to the coarser of the precisions
|
| 1037 |
-
of `time_t` and `time_point`. It is implementation
|
| 1038 |
values are rounded or truncated to the required precision.
|
| 1039 |
|
| 1040 |
#### Class `steady_clock` <a id="time.clock.steady">[[time.clock.steady]]</a>
|
| 1041 |
|
| 1042 |
Objects of class `steady_clock` represent clocks for which values of
|
|
@@ -1045,14 +1193,14 @@ values of `time_point` advance at a steady rate relative to real time.
|
|
| 1045 |
That is, the clock may not be adjusted.
|
| 1046 |
|
| 1047 |
``` cpp
|
| 1048 |
class steady_clock {
|
| 1049 |
public:
|
| 1050 |
-
|
| 1051 |
-
|
| 1052 |
-
|
| 1053 |
-
|
| 1054 |
static constexpr bool is_steady = true;
|
| 1055 |
|
| 1056 |
static time_point now() noexcept;
|
| 1057 |
};
|
| 1058 |
```
|
|
@@ -1064,26 +1212,51 @@ shortest tick period. `high_resolution_clock` may be a synonym for
|
|
| 1064 |
`system_clock` or `steady_clock`.
|
| 1065 |
|
| 1066 |
``` cpp
|
| 1067 |
class high_resolution_clock {
|
| 1068 |
public:
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
| 1072 |
-
|
| 1073 |
static constexpr bool is_steady = unspecified;
|
| 1074 |
|
| 1075 |
static time_point now() noexcept;
|
| 1076 |
};
|
| 1077 |
```
|
| 1078 |
|
| 1079 |
-
###
|
| 1080 |
|
| 1081 |
-
|
|
|
|
|
|
|
|
|
|
| 1082 |
|
| 1083 |
-
|
| 1084 |
-
|
| 1085 |
-
|
| 1086 |
-
|
| 1087 |
|
| 1088 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1089 |
|
|
|
|
| 1 |
## Time utilities <a id="time">[[time]]</a>
|
| 2 |
|
| 3 |
### In general <a id="time.general">[[time.general]]</a>
|
| 4 |
|
| 5 |
This subclause describes the chrono library ([[time.syn]]) and various
|
| 6 |
+
C functions ([[ctime.syn]]) that provide generally useful time
|
| 7 |
utilities.
|
| 8 |
|
| 9 |
### Header `<chrono>` synopsis <a id="time.syn">[[time.syn]]</a>
|
| 10 |
|
| 11 |
``` cpp
|
| 12 |
namespace std {
|
| 13 |
namespace chrono {
|
|
|
|
| 14 |
// [time.duration], class template duration
|
| 15 |
template <class Rep, class Period = ratio<1>> class duration;
|
| 16 |
|
| 17 |
// [time.point], class template time_point
|
| 18 |
template <class Clock, class Duration = typename Clock::duration> class time_point;
|
| 19 |
+
}
|
| 20 |
|
| 21 |
+
// [time.traits.specializations], common_type specializations
|
|
|
|
|
|
|
| 22 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 23 |
+
struct common_type<chrono::duration<Rep1, Period1>,
|
| 24 |
+
chrono::duration<Rep2, Period2>>;
|
| 25 |
|
| 26 |
template <class Clock, class Duration1, class Duration2>
|
| 27 |
+
struct common_type<chrono::time_point<Clock, Duration1>,
|
| 28 |
+
chrono::time_point<Clock, Duration2>>;
|
| 29 |
|
| 30 |
namespace chrono {
|
|
|
|
| 31 |
// [time.traits], customization traits
|
| 32 |
template <class Rep> struct treat_as_floating_point;
|
| 33 |
template <class Rep> struct duration_values;
|
| 34 |
+
template <class Rep> inline constexpr bool treat_as_floating_point_v
|
| 35 |
+
= treat_as_floating_point<Rep>::value;
|
| 36 |
|
| 37 |
// [time.duration.nonmember], duration arithmetic
|
| 38 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 39 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 40 |
+
constexpr operator+(const duration<Rep1, Period1>& lhs,
|
| 41 |
+
const duration<Rep2, Period2>& rhs);
|
| 42 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 43 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 44 |
+
constexpr operator-(const duration<Rep1, Period1>& lhs,
|
| 45 |
+
const duration<Rep2, Period2>& rhs);
|
| 46 |
template <class Rep1, class Period, class Rep2>
|
| 47 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 48 |
constexpr operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 49 |
template <class Rep1, class Rep2, class Period>
|
| 50 |
duration<common_type_t<Rep1, Rep2>, Period>
|
|
|
|
| 52 |
template <class Rep1, class Period, class Rep2>
|
| 53 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 54 |
constexpr operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 55 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 56 |
common_type_t<Rep1, Rep2>
|
| 57 |
+
constexpr operator/(const duration<Rep1, Period1>& lhs,
|
| 58 |
+
const duration<Rep2, Period2>& rhs);
|
| 59 |
template <class Rep1, class Period, class Rep2>
|
| 60 |
duration<common_type_t<Rep1, Rep2>, Period>
|
| 61 |
constexpr operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 62 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 63 |
common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 64 |
+
constexpr operator%(const duration<Rep1, Period1>& lhs,
|
| 65 |
+
const duration<Rep2, Period2>& rhs);
|
| 66 |
|
| 67 |
// [time.duration.comparisons], duration comparisons
|
| 68 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 69 |
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 70 |
const duration<Rep2, Period2>& rhs);
|
|
|
|
| 85 |
const duration<Rep2, Period2>& rhs);
|
| 86 |
|
| 87 |
// [time.duration.cast], duration_cast
|
| 88 |
template <class ToDuration, class Rep, class Period>
|
| 89 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 90 |
+
template <class ToDuration, class Rep, class Period>
|
| 91 |
+
constexpr ToDuration floor(const duration<Rep, Period>& d);
|
| 92 |
+
template <class ToDuration, class Rep, class Period>
|
| 93 |
+
constexpr ToDuration ceil(const duration<Rep, Period>& d);
|
| 94 |
+
template <class ToDuration, class Rep, class Period>
|
| 95 |
+
constexpr ToDuration round(const duration<Rep, Period>& d);
|
| 96 |
|
| 97 |
// convenience typedefs
|
| 98 |
+
using nanoseconds = duration<signed integer type of at least 64 bits, nano>;
|
| 99 |
+
using microseconds = duration<signed integer type of at least 55 bits, micro>;
|
| 100 |
+
using milliseconds = duration<signed integer type of at least 45 bits, milli>;
|
| 101 |
+
using seconds = duration<signed integer type of at least 35 bits>;
|
| 102 |
+
using minutes = duration<signed integer type of at least 29 bits, ratio< 60>>;
|
| 103 |
+
using hours = duration<signed integer type of at least 23 bits, ratio<3600>>;
|
| 104 |
|
| 105 |
// [time.point.nonmember], time_point arithmetic
|
| 106 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 107 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 108 |
+
operator+(const time_point<Clock, Duration1>& lhs,
|
| 109 |
+
const duration<Rep2, Period2>& rhs);
|
| 110 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 111 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 112 |
+
operator+(const duration<Rep1, Period1>& lhs,
|
| 113 |
+
const time_point<Clock, Duration2>& rhs);
|
| 114 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 115 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 116 |
+
operator-(const time_point<Clock, Duration1>& lhs,
|
| 117 |
+
const duration<Rep2, Period2>& rhs);
|
| 118 |
template <class Clock, class Duration1, class Duration2>
|
| 119 |
constexpr common_type_t<Duration1, Duration2>
|
| 120 |
+
operator-(const time_point<Clock, Duration1>& lhs,
|
| 121 |
+
const time_point<Clock, Duration2>& rhs);
|
| 122 |
|
| 123 |
+
// [time.point.comparisons], time_point comparisons
|
| 124 |
template <class Clock, class Duration1, class Duration2>
|
| 125 |
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 126 |
const time_point<Clock, Duration2>& rhs);
|
| 127 |
template <class Clock, class Duration1, class Duration2>
|
| 128 |
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
|
|
|
| 142 |
|
| 143 |
// [time.point.cast], time_point_cast
|
| 144 |
template <class ToDuration, class Clock, class Duration>
|
| 145 |
constexpr time_point<Clock, ToDuration>
|
| 146 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 147 |
+
template <class ToDuration, class Clock, class Duration>
|
| 148 |
+
constexpr time_point<Clock, ToDuration>
|
| 149 |
+
floor(const time_point<Clock, Duration>& tp);
|
| 150 |
+
template <class ToDuration, class Clock, class Duration>
|
| 151 |
+
constexpr time_point<Clock, ToDuration>
|
| 152 |
+
ceil(const time_point<Clock, Duration>& tp);
|
| 153 |
+
template <class ToDuration, class Clock, class Duration>
|
| 154 |
+
constexpr time_point<Clock, ToDuration>
|
| 155 |
+
round(const time_point<Clock, Duration>& tp);
|
| 156 |
+
|
| 157 |
+
// [time.duration.alg], specialized algorithms
|
| 158 |
+
template <class Rep, class Period>
|
| 159 |
+
constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
|
| 160 |
|
| 161 |
// [time.clock], clocks
|
| 162 |
class system_clock;
|
| 163 |
class steady_clock;
|
| 164 |
class high_resolution_clock;
|
| 165 |
+
}
|
|
|
|
| 166 |
|
| 167 |
inline namespace literals {
|
| 168 |
inline namespace chrono_literals {
|
| 169 |
+
// [time.duration.literals], suffixes for duration literals
|
|
|
|
| 170 |
constexpr chrono::hours operator""h(unsigned long long);
|
| 171 |
constexpr chrono::duration<unspecified, ratio<3600,1>> operator""h(long double);
|
| 172 |
constexpr chrono::minutes operator""min(unsigned long long);
|
| 173 |
constexpr chrono::duration<unspecified, ratio<60,1>> operator""min(long double);
|
| 174 |
constexpr chrono::seconds operator""s(unsigned long long);
|
|
|
|
| 177 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double);
|
| 178 |
constexpr chrono::microseconds operator""us(unsigned long long);
|
| 179 |
constexpr chrono::duration<unspecified, micro> operator""us(long double);
|
| 180 |
constexpr chrono::nanoseconds operator""ns(unsigned long long);
|
| 181 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double);
|
| 182 |
+
}
|
| 183 |
+
}
|
|
|
|
| 184 |
|
| 185 |
namespace chrono {
|
|
|
|
| 186 |
using namespace literals::chrono_literals;
|
| 187 |
+
}
|
| 188 |
+
}
|
|
|
|
|
|
|
| 189 |
```
|
| 190 |
|
| 191 |
### Clock requirements <a id="time.clock.req">[[time.clock.req]]</a>
|
| 192 |
|
| 193 |
A clock is a bundle consisting of a `duration`, a `time_point`, and a
|
|
|
|
| 196 |
shall meet the requirements in Table [[tab:time.clock]].
|
| 197 |
|
| 198 |
In Table [[tab:time.clock]] `C1` and `C2` denote clock types. `t1` and
|
| 199 |
`t2` are values returned by `C1::now()` where the call returning `t1`
|
| 200 |
happens before ([[intro.multithread]]) the call returning `t2` and both
|
| 201 |
+
of these calls occur before `C1::time_point::max()`.
|
|
|
|
| 202 |
|
| 203 |
+
[*Note 1*: This means `C1` did not wrap around between `t1` and
|
| 204 |
+
`t2`. — *end note*]
|
| 205 |
+
|
| 206 |
+
[*Note 2*: The relative difference in durations between those reported
|
| 207 |
+
by a given clock and the SI definition is a measure of the quality of
|
| 208 |
+
implementation. — *end note*]
|
| 209 |
|
| 210 |
A type `TC` meets the `TrivialClock` requirements if:
|
| 211 |
|
| 212 |
- `TC` satisfies the `Clock` requirements ([[time.clock.req]]),
|
| 213 |
- the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the
|
| 214 |
+
requirements of `EqualityComparable` (Table
|
| 215 |
+
[[tab:equalitycomparable]]), `LessThanComparable` (Table
|
| 216 |
+
[[tab:lessthancomparable]]), `DefaultConstructible` (Table
|
| 217 |
+
[[tab:defaultconstructible]]), `CopyConstructible` (Table
|
| 218 |
+
[[tab:copyconstructible]]), `CopyAssignable` (Table
|
| 219 |
+
[[tab:copyassignable]]), `Destructible` (Table [[tab:destructible]]),
|
| 220 |
and the requirements of numeric types ([[numeric.requirements]]).
|
| 221 |
+
\[*Note 3*: This means, in particular, that operations on these types
|
| 222 |
+
will not throw exceptions. — *end note*]
|
| 223 |
- lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point`
|
| 224 |
are swappable ([[swappable.requirements]]),
|
| 225 |
- the function `TC::now()` does not throw exceptions, and
|
| 226 |
- the type `TC::time_point::clock` meets the `TrivialClock`
|
| 227 |
requirements, recursively.
|
|
|
|
| 235 |
: is_floating_point<Rep> { };
|
| 236 |
```
|
| 237 |
|
| 238 |
The `duration` template uses the `treat_as_floating_point` trait to help
|
| 239 |
determine if a `duration` object can be converted to another `duration`
|
| 240 |
+
with a different tick `period`. If `treat_as_floating_point_v<Rep>` is
|
| 241 |
+
`true`, then implicit conversions are allowed among `duration`s.
|
| 242 |
Otherwise, the implicit convertibility depends on the tick `period`s of
|
| 243 |
+
the `duration`s.
|
| 244 |
+
|
| 245 |
+
[*Note 1*: The intention of this trait is to indicate whether a given
|
| 246 |
+
class behaves like a floating-point type, and thus allows division of
|
| 247 |
+
one value by another with acceptable loss of precision. If
|
| 248 |
+
`treat_as_floating_point_v<Rep>` is `false`, `Rep` will be treated as if
|
| 249 |
+
it behaved like an integral type for the purpose of these
|
| 250 |
+
conversions. — *end note*]
|
| 251 |
|
| 252 |
#### `duration_values` <a id="time.traits.duration_values">[[time.traits.duration_values]]</a>
|
| 253 |
|
| 254 |
``` cpp
|
| 255 |
template <class Rep>
|
|
|
|
| 270 |
|
| 271 |
``` cpp
|
| 272 |
static constexpr Rep zero();
|
| 273 |
```
|
| 274 |
|
| 275 |
+
*Returns:* `Rep(0)`.
|
|
|
|
| 276 |
|
| 277 |
+
[*Note 1*: `Rep(0)` is specified instead of `Rep()` because `Rep()` may
|
| 278 |
+
have some other meaning, such as an uninitialized value. — *end note*]
|
| 279 |
+
|
| 280 |
+
*Remarks:* The value returned shall be the additive identity.
|
| 281 |
|
| 282 |
``` cpp
|
| 283 |
static constexpr Rep min();
|
| 284 |
```
|
| 285 |
|
| 286 |
*Returns:* `numeric_limits<Rep>::lowest()`.
|
| 287 |
|
| 288 |
+
*Remarks:* The value returned shall compare less than or equal to
|
| 289 |
+
`zero()`.
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
static constexpr Rep max();
|
| 293 |
```
|
| 294 |
|
| 295 |
*Returns:* `numeric_limits<Rep>::max()`.
|
| 296 |
|
| 297 |
+
*Remarks:* The value returned shall compare greater than `zero()`.
|
| 298 |
|
| 299 |
#### Specializations of `common_type` <a id="time.traits.specializations">[[time.traits.specializations]]</a>
|
| 300 |
|
| 301 |
``` cpp
|
| 302 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 303 |
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> {
|
| 304 |
+
using type = chrono::duration<common_type_t<Rep1, Rep2>, see below>;
|
| 305 |
};
|
| 306 |
```
|
| 307 |
|
| 308 |
The `period` of the `duration` indicated by this specialization of
|
| 309 |
`common_type` shall be the greatest common divisor of `Period1` and
|
| 310 |
+
`Period2`.
|
| 311 |
+
|
| 312 |
+
[*Note 1*: This can be computed by forming a ratio of the greatest
|
| 313 |
common divisor of `Period1::num` and `Period2::num` and the least common
|
| 314 |
+
multiple of `Period1::den` and `Period2::den`. — *end note*]
|
| 315 |
|
| 316 |
+
[*Note 2*: The `typedef` name `type` is a synonym for the `duration`
|
| 317 |
+
with the largest tick `period` possible where both `duration` arguments
|
| 318 |
+
will convert to it without requiring a division operation. The
|
| 319 |
+
representation of this type is intended to be able to hold any value
|
| 320 |
+
resulting from this conversion with no truncation error, although
|
| 321 |
+
floating-point durations may have round-off errors. — *end note*]
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
template <class Clock, class Duration1, class Duration2>
|
| 325 |
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> {
|
| 326 |
+
using type = chrono::time_point<Clock, common_type_t<Duration1, Duration2>>;
|
| 327 |
};
|
| 328 |
```
|
| 329 |
|
| 330 |
The common type of two `time_point` types is a `time_point` with the
|
| 331 |
same clock as the two types and the common type of their two
|
|
|
|
| 341 |
|
| 342 |
``` cpp
|
| 343 |
template <class Rep, class Period = ratio<1>>
|
| 344 |
class duration {
|
| 345 |
public:
|
| 346 |
+
using rep = Rep;
|
| 347 |
+
using period = typename Period::type;
|
| 348 |
private:
|
| 349 |
rep rep_; // exposition only
|
| 350 |
public:
|
| 351 |
+
// [time.duration.cons], construct/copy/destroy
|
| 352 |
constexpr duration() = default;
|
| 353 |
template <class Rep2>
|
| 354 |
constexpr explicit duration(const Rep2& r);
|
| 355 |
template <class Rep2, class Period2>
|
| 356 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 357 |
~duration() = default;
|
| 358 |
duration(const duration&) = default;
|
| 359 |
duration& operator=(const duration&) = default;
|
| 360 |
|
| 361 |
+
// [time.duration.observer], observer
|
| 362 |
constexpr rep count() const;
|
| 363 |
|
| 364 |
+
// [time.duration.arithmetic], arithmetic
|
| 365 |
+
constexpr common_type_t<duration> operator+() const;
|
| 366 |
+
constexpr common_type_t<duration> operator-() const;
|
| 367 |
+
constexpr duration& operator++();
|
| 368 |
+
constexpr duration operator++(int);
|
| 369 |
+
constexpr duration& operator--();
|
| 370 |
+
constexpr duration operator--(int);
|
| 371 |
|
| 372 |
+
constexpr duration& operator+=(const duration& d);
|
| 373 |
+
constexpr duration& operator-=(const duration& d);
|
| 374 |
|
| 375 |
+
constexpr duration& operator*=(const rep& rhs);
|
| 376 |
+
constexpr duration& operator/=(const rep& rhs);
|
| 377 |
+
constexpr duration& operator%=(const rep& rhs);
|
| 378 |
+
constexpr duration& operator%=(const duration& rhs);
|
| 379 |
|
| 380 |
+
// [time.duration.special], special values
|
| 381 |
static constexpr duration zero();
|
| 382 |
static constexpr duration min();
|
| 383 |
static constexpr duration max();
|
| 384 |
};
|
| 385 |
```
|
| 386 |
|
| 387 |
+
`Rep` shall be an arithmetic type or a class emulating an arithmetic
|
| 388 |
+
type. If `duration` is instantiated with a `duration` type as the
|
| 389 |
+
argument for the template parameter `Rep`, the program is ill-formed.
|
| 390 |
|
| 391 |
+
If `Period` is not a specialization of `ratio`, the program is
|
| 392 |
+
ill-formed. If `Period::num` is not positive, the program is ill-formed.
|
| 393 |
|
| 394 |
+
Members of `duration` shall not throw exceptions other than those thrown
|
| 395 |
+
by the indicated operations on their representations.
|
| 396 |
|
| 397 |
+
The defaulted copy constructor of duration shall be a constexpr function
|
| 398 |
+
if and only if the required initialization of the member `rep_` for copy
|
| 399 |
+
and move, respectively, would satisfy the requirements for a constexpr
|
| 400 |
+
function.
|
| 401 |
|
| 402 |
+
[*Example 1*:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
``` cpp
|
| 405 |
duration<long, ratio<60>> d0; // holds a count of minutes using a long
|
| 406 |
duration<long long, milli> d1; // holds a count of milliseconds using a long long
|
| 407 |
duration<double, ratio<1, 30>> d2; // holds a count with a tick period of $\frac{1}{30}$ of a second
|
| 408 |
// (30 Hz) using a double
|
| 409 |
```
|
| 410 |
|
| 411 |
+
— *end example*]
|
| 412 |
+
|
| 413 |
#### `duration` constructors <a id="time.duration.cons">[[time.duration.cons]]</a>
|
| 414 |
|
| 415 |
``` cpp
|
| 416 |
template <class Rep2>
|
| 417 |
constexpr explicit duration(const Rep2& r);
|
| 418 |
```
|
| 419 |
|
| 420 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 421 |
unless `Rep2` is implicitly convertible to `rep` and
|
| 422 |
|
| 423 |
+
- `treat_as_floating_point_v<rep>` is `true` or
|
| 424 |
+
- `treat_as_floating_point_v<Rep2>` is `false`.
|
| 425 |
+
|
| 426 |
+
[*Example 1*:
|
| 427 |
|
| 428 |
``` cpp
|
| 429 |
duration<int, milli> d(3); // OK
|
| 430 |
duration<int, milli> d(3.5); // error
|
| 431 |
```
|
| 432 |
|
| 433 |
+
— *end example*]
|
| 434 |
+
|
| 435 |
*Effects:* Constructs an object of type `duration`.
|
| 436 |
|
| 437 |
+
*Postconditions:* `count() == static_cast<rep>(r)`.
|
| 438 |
|
| 439 |
``` cpp
|
| 440 |
template <class Rep2, class Period2>
|
| 441 |
constexpr duration(const duration<Rep2, Period2>& d);
|
| 442 |
```
|
| 443 |
|
| 444 |
*Remarks:* This constructor shall not participate in overload resolution
|
| 445 |
unless no overflow is induced in the conversion and
|
| 446 |
+
`treat_as_floating_point_v<rep>` is `true` or both
|
| 447 |
`ratio_divide<Period2, period>::den` is `1` and
|
| 448 |
+
`treat_as_floating_point_v<Rep2>` is `false`.
|
| 449 |
+
|
| 450 |
+
[*Note 1*: This requirement prevents implicit truncation error when
|
| 451 |
+
converting between integral-based `duration` types. Such a construction
|
| 452 |
+
could easily lead to confusion about the value of the
|
| 453 |
+
`duration`. — *end note*]
|
| 454 |
+
|
| 455 |
+
[*Example 2*:
|
| 456 |
|
| 457 |
``` cpp
|
| 458 |
duration<int, milli> ms(3);
|
| 459 |
duration<int, micro> us = ms; // OK
|
| 460 |
duration<int, milli> ms2 = us; // error
|
| 461 |
```
|
| 462 |
|
| 463 |
+
— *end example*]
|
| 464 |
+
|
| 465 |
*Effects:* Constructs an object of type `duration`, constructing `rep_`
|
| 466 |
from
|
| 467 |
`duration_cast<duration>(d).count()`.
|
| 468 |
|
| 469 |
#### `duration` observer <a id="time.duration.observer">[[time.duration.observer]]</a>
|
|
|
|
| 475 |
*Returns:* `rep_`.
|
| 476 |
|
| 477 |
#### `duration` arithmetic <a id="time.duration.arithmetic">[[time.duration.arithmetic]]</a>
|
| 478 |
|
| 479 |
``` cpp
|
| 480 |
+
constexpr common_type_t<duration> operator+() const;
|
| 481 |
```
|
| 482 |
|
| 483 |
+
*Returns:* `common_type_t<duration>(*this)`.
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
+
constexpr common_type_t<duration> operator-() const;
|
| 487 |
```
|
| 488 |
|
| 489 |
+
*Returns:* `common_type_t<duration>(-rep_)`.
|
| 490 |
|
| 491 |
``` cpp
|
| 492 |
+
constexpr duration& operator++();
|
| 493 |
```
|
| 494 |
|
| 495 |
+
*Effects:* As if by `++rep_`.
|
| 496 |
|
| 497 |
*Returns:* `*this`.
|
| 498 |
|
| 499 |
``` cpp
|
| 500 |
+
constexpr duration operator++(int);
|
| 501 |
```
|
| 502 |
|
| 503 |
+
*Returns:* `duration(rep_++)`.
|
| 504 |
|
| 505 |
``` cpp
|
| 506 |
+
constexpr duration& operator--();
|
| 507 |
```
|
| 508 |
|
| 509 |
+
*Effects:* As if by `–rep_`.
|
| 510 |
|
| 511 |
*Returns:* `*this`.
|
| 512 |
|
| 513 |
``` cpp
|
| 514 |
+
constexpr duration operator--(int);
|
| 515 |
```
|
| 516 |
|
| 517 |
+
*Returns:* `duration(rep_--)`.
|
| 518 |
|
| 519 |
``` cpp
|
| 520 |
+
constexpr duration& operator+=(const duration& d);
|
| 521 |
```
|
| 522 |
|
| 523 |
+
*Effects:* As if by: `rep_ += d.count();`
|
| 524 |
|
| 525 |
*Returns:* `*this`.
|
| 526 |
|
| 527 |
``` cpp
|
| 528 |
+
constexpr duration& operator-=(const duration& d);
|
| 529 |
```
|
| 530 |
|
| 531 |
+
*Effects:* As if by: `rep_ -= d.count();`
|
| 532 |
|
| 533 |
*Returns:* `*this`.
|
| 534 |
|
| 535 |
``` cpp
|
| 536 |
+
constexpr duration& operator*=(const rep& rhs);
|
| 537 |
```
|
| 538 |
|
| 539 |
+
*Effects:* As if by: `rep_ *= rhs;`
|
| 540 |
|
| 541 |
*Returns:* `*this`.
|
| 542 |
|
| 543 |
``` cpp
|
| 544 |
+
constexpr duration& operator/=(const rep& rhs);
|
| 545 |
```
|
| 546 |
|
| 547 |
+
*Effects:* As if by: `rep_ /= rhs;`
|
| 548 |
|
| 549 |
*Returns:* `*this`.
|
| 550 |
|
| 551 |
``` cpp
|
| 552 |
+
constexpr duration& operator%=(const rep& rhs);
|
| 553 |
```
|
| 554 |
|
| 555 |
+
*Effects:* As if by: `rep_ %= rhs;`
|
| 556 |
|
| 557 |
*Returns:* `*this`.
|
| 558 |
|
| 559 |
``` cpp
|
| 560 |
+
constexpr duration& operator%=(const duration& rhs);
|
| 561 |
```
|
| 562 |
|
| 563 |
+
*Effects:* As if by: `rep_ %= rhs.count();`
|
| 564 |
|
| 565 |
*Returns:* `*this`.
|
| 566 |
|
| 567 |
#### `duration` special values <a id="time.duration.special">[[time.duration.special]]</a>
|
| 568 |
|
|
|
|
| 593 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 594 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 595 |
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 596 |
```
|
| 597 |
|
| 598 |
+
*Returns:* `CD(CD(lhs).count() + CD(rhs).count())`.
|
| 599 |
|
| 600 |
``` cpp
|
| 601 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 602 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 603 |
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 604 |
```
|
| 605 |
|
| 606 |
+
*Returns:* `CD(CD(lhs).count() - CD(rhs).count())`.
|
| 607 |
|
| 608 |
``` cpp
|
| 609 |
template <class Rep1, class Period, class Rep2>
|
| 610 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 611 |
operator*(const duration<Rep1, Period>& d, const Rep2& s);
|
| 612 |
```
|
| 613 |
|
| 614 |
*Remarks:* This operator shall not participate in overload resolution
|
| 615 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)`.
|
| 616 |
|
| 617 |
+
*Returns:* `CD(CD(d).count() * s)`.
|
| 618 |
|
| 619 |
``` cpp
|
| 620 |
template <class Rep1, class Rep2, class Period>
|
| 621 |
constexpr duration<common_type_t<Rep1, Rep2>, Period>
|
| 622 |
operator*(const Rep1& s, const duration<Rep2, Period>& d);
|
|
|
|
| 633 |
operator/(const duration<Rep1, Period>& d, const Rep2& s);
|
| 634 |
```
|
| 635 |
|
| 636 |
*Remarks:* This operator shall not participate in overload resolution
|
| 637 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 638 |
+
is not a specialization of `duration`.
|
| 639 |
|
| 640 |
+
*Returns:* `CD(CD(d).count() / s)`.
|
| 641 |
|
| 642 |
``` cpp
|
| 643 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 644 |
constexpr common_type_t<Rep1, Rep2>
|
| 645 |
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
|
|
|
| 653 |
operator%(const duration<Rep1, Period>& d, const Rep2& s);
|
| 654 |
```
|
| 655 |
|
| 656 |
*Remarks:* This operator shall not participate in overload resolution
|
| 657 |
unless `Rep2` is implicitly convertible to `CR(Rep1, Rep2)` and `Rep2`
|
| 658 |
+
is not a specialization of `duration`.
|
| 659 |
|
| 660 |
+
*Returns:* `CD(CD(d).count() % s)`.
|
| 661 |
|
| 662 |
``` cpp
|
| 663 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 664 |
constexpr common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
|
| 665 |
operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 666 |
```
|
| 667 |
|
| 668 |
+
*Returns:* `CD(CD(lhs).count() % CD(rhs).count())`.
|
| 669 |
|
| 670 |
#### `duration` comparisons <a id="time.duration.comparisons">[[time.duration.comparisons]]</a>
|
| 671 |
|
| 672 |
In the function descriptions that follow, `CT` represents
|
| 673 |
`common_type_t<A, B>`, where `A` and `B` are the types of the two
|
| 674 |
arguments to the function.
|
| 675 |
|
| 676 |
``` cpp
|
| 677 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 678 |
+
constexpr bool operator==(const duration<Rep1, Period1>& lhs,
|
| 679 |
+
const duration<Rep2, Period2>& rhs);
|
| 680 |
```
|
| 681 |
|
| 682 |
+
*Returns:* *`CT`*`(lhs).count() == `*`CT`*`(rhs).count()`.
|
| 683 |
|
| 684 |
``` cpp
|
| 685 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 686 |
+
constexpr bool operator!=(const duration<Rep1, Period1>& lhs,
|
| 687 |
+
const duration<Rep2, Period2>& rhs);
|
| 688 |
```
|
| 689 |
|
| 690 |
*Returns:* `!(lhs == rhs)`.
|
| 691 |
|
| 692 |
``` cpp
|
| 693 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 694 |
+
constexpr bool operator<(const duration<Rep1, Period1>& lhs,
|
| 695 |
+
const duration<Rep2, Period2>& rhs);
|
| 696 |
```
|
| 697 |
|
| 698 |
+
*Returns:* *`CT`*`(lhs).count() < `*`CT`*`(rhs).count()`.
|
| 699 |
|
| 700 |
``` cpp
|
| 701 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 702 |
+
constexpr bool operator<=(const duration<Rep1, Period1>& lhs,
|
| 703 |
+
const duration<Rep2, Period2>& rhs);
|
| 704 |
```
|
| 705 |
|
| 706 |
*Returns:* `!(rhs < lhs)`.
|
| 707 |
|
| 708 |
``` cpp
|
| 709 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 710 |
+
constexpr bool operator>(const duration<Rep1, Period1>& lhs,
|
| 711 |
+
const duration<Rep2, Period2>& rhs);
|
| 712 |
```
|
| 713 |
|
| 714 |
*Returns:* `rhs < lhs`.
|
| 715 |
|
| 716 |
``` cpp
|
| 717 |
template <class Rep1, class Period1, class Rep2, class Period2>
|
| 718 |
+
constexpr bool operator>=(const duration<Rep1, Period1>& lhs,
|
| 719 |
+
const duration<Rep2, Period2>& rhs);
|
| 720 |
```
|
| 721 |
|
| 722 |
*Returns:* `!(lhs < rhs)`.
|
| 723 |
|
| 724 |
#### `duration_cast` <a id="time.duration.cast">[[time.duration.cast]]</a>
|
|
|
|
| 727 |
template <class ToDuration, class Rep, class Period>
|
| 728 |
constexpr ToDuration duration_cast(const duration<Rep, Period>& d);
|
| 729 |
```
|
| 730 |
|
| 731 |
*Remarks:* This function shall not participate in overload resolution
|
| 732 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 733 |
|
| 734 |
*Returns:* Let `CF` be
|
| 735 |
`ratio_divide<Period, typename ToDuration::period>`, and `CR` be
|
| 736 |
+
`common_type<` `typename ToDuration::rep, Rep, intmax_t>::type`.
|
| 737 |
|
| 738 |
- If `CF::num == 1` and `CF::den == 1`, returns
|
| 739 |
``` cpp
|
| 740 |
ToDuration(static_cast<typename ToDuration::rep>(d.count()))
|
| 741 |
```
|
|
|
|
| 753 |
``` cpp
|
| 754 |
ToDuration(static_cast<typename ToDuration::rep>(
|
| 755 |
static_cast<CR>(d.count()) * static_cast<CR>(CF::num) / static_cast<CR>(CF::den)))
|
| 756 |
```
|
| 757 |
|
| 758 |
+
[*Note 1*: This function does not use any implicit conversions; all
|
| 759 |
conversions are done with `static_cast`. It avoids multiplications and
|
| 760 |
divisions when it is known at compile time that one or more arguments
|
| 761 |
is 1. Intermediate computations are carried out in the widest
|
| 762 |
representation and only converted to the destination representation at
|
| 763 |
+
the final step. — *end note*]
|
| 764 |
+
|
| 765 |
+
``` cpp
|
| 766 |
+
template <class ToDuration, class Rep, class Period>
|
| 767 |
+
constexpr ToDuration floor(const duration<Rep, Period>& d);
|
| 768 |
+
```
|
| 769 |
+
|
| 770 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 771 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 772 |
+
|
| 773 |
+
*Returns:* The greatest result `t` representable in `ToDuration` for
|
| 774 |
+
which `t <= d`.
|
| 775 |
+
|
| 776 |
+
``` cpp
|
| 777 |
+
template <class ToDuration, class Rep, class Period>
|
| 778 |
+
constexpr ToDuration ceil(const duration<Rep, Period>& d);
|
| 779 |
+
```
|
| 780 |
+
|
| 781 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 782 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 783 |
+
|
| 784 |
+
*Returns:* The least result `t` representable in `ToDuration` for which
|
| 785 |
+
`t >= d`.
|
| 786 |
+
|
| 787 |
+
``` cpp
|
| 788 |
+
template <class ToDuration, class Rep, class Period>
|
| 789 |
+
constexpr ToDuration round(const duration<Rep, Period>& d);
|
| 790 |
+
```
|
| 791 |
+
|
| 792 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 793 |
+
unless `ToDuration` is a specialization of `duration`, and
|
| 794 |
+
`treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
|
| 795 |
+
|
| 796 |
+
*Returns:* The value of `ToDuration` that is closest to `d`. If there
|
| 797 |
+
are two closest values, then return the value `t` for which
|
| 798 |
+
`t % 2 == 0`.
|
| 799 |
|
| 800 |
#### Suffixes for duration literals <a id="time.duration.literals">[[time.duration.literals]]</a>
|
| 801 |
|
| 802 |
This section describes literal suffixes for constructing duration
|
| 803 |
literals. The suffixes `h`, `min`, `s`, `ms`, `us`, `ns` denote duration
|
| 804 |
values of the corresponding types `hours`, `minutes`, `seconds`,
|
| 805 |
`milliseconds`, `microseconds`, and `nanoseconds` respectively if they
|
| 806 |
are applied to integral literals.
|
| 807 |
|
| 808 |
+
If any of these suffixes are applied to a floating-point literal the
|
| 809 |
+
result is a `chrono::duration` literal with an unspecified
|
| 810 |
+
floating-point representation.
|
| 811 |
|
| 812 |
If any of these suffixes are applied to an integer literal and the
|
| 813 |
resulting `chrono::duration` value cannot be represented in the result
|
| 814 |
type because of overflow, the program is ill-formed.
|
| 815 |
|
| 816 |
+
[*Example 1*:
|
| 817 |
+
|
| 818 |
The following code shows some duration literals.
|
| 819 |
|
| 820 |
``` cpp
|
| 821 |
using namespace std::chrono_literals;
|
| 822 |
auto constexpr aday=24h;
|
| 823 |
auto constexpr lesson=45min;
|
| 824 |
auto constexpr halfanhour=0.5h;
|
| 825 |
```
|
| 826 |
|
| 827 |
+
— *end example*]
|
| 828 |
+
|
| 829 |
``` cpp
|
| 830 |
constexpr chrono::hours operator""h(unsigned long long hours);
|
| 831 |
constexpr chrono::duration<unspecified, ratio<3600, 1>> operator""h(long double hours);
|
| 832 |
```
|
| 833 |
|
|
|
|
| 839 |
```
|
| 840 |
|
| 841 |
*Returns:* A `duration` literal representing `minutes` minutes.
|
| 842 |
|
| 843 |
``` cpp
|
| 844 |
+
constexpr chrono::seconds \itcorr operator""s(unsigned long long sec);
|
| 845 |
constexpr chrono::duration<unspecified> operator""s(long double sec);
|
| 846 |
```
|
| 847 |
|
| 848 |
*Returns:* A `duration` literal representing `sec` seconds.
|
| 849 |
|
| 850 |
+
[*Note 1*: The same suffix `s` is used for `basic_string` but there is
|
| 851 |
+
no conflict, since duration suffixes apply to numbers and string literal
|
| 852 |
+
suffixes apply to character array literals. — *end note*]
|
| 853 |
|
| 854 |
``` cpp
|
| 855 |
constexpr chrono::milliseconds operator""ms(unsigned long long msec);
|
| 856 |
constexpr chrono::duration<unspecified, milli> operator""ms(long double msec);
|
| 857 |
```
|
|
|
|
| 870 |
constexpr chrono::duration<unspecified, nano> operator""ns(long double nsec);
|
| 871 |
```
|
| 872 |
|
| 873 |
*Returns:* A `duration` literal representing `nsec` nanoseconds.
|
| 874 |
|
| 875 |
+
#### `duration` algorithms <a id="time.duration.alg">[[time.duration.alg]]</a>
|
| 876 |
+
|
| 877 |
+
``` cpp
|
| 878 |
+
template <class Rep, class Period>
|
| 879 |
+
constexpr duration<Rep, Period> abs(duration<Rep, Period> d);
|
| 880 |
+
```
|
| 881 |
+
|
| 882 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 883 |
+
unless `numeric_limits<Rep>::is_signed` is `true`.
|
| 884 |
+
|
| 885 |
+
*Returns:* If `d >= d.zero()`, return `d`, otherwise return `-d`.
|
| 886 |
+
|
| 887 |
### Class template `time_point` <a id="time.point">[[time.point]]</a>
|
| 888 |
|
| 889 |
``` cpp
|
| 890 |
template <class Clock, class Duration = typename Clock::duration>
|
| 891 |
class time_point {
|
| 892 |
public:
|
| 893 |
+
using clock = Clock;
|
| 894 |
+
using duration = Duration;
|
| 895 |
+
using rep = typename duration::rep;
|
| 896 |
+
using period = typename duration::period;
|
| 897 |
private:
|
| 898 |
duration d_; // exposition only
|
| 899 |
|
| 900 |
public:
|
| 901 |
+
// [time.point.cons], construct
|
| 902 |
constexpr time_point(); // has value epoch
|
| 903 |
constexpr explicit time_point(const duration& d); // same as time_point() + d
|
| 904 |
template <class Duration2>
|
| 905 |
constexpr time_point(const time_point<clock, Duration2>& t);
|
| 906 |
|
| 907 |
+
// [time.point.observer], observer
|
| 908 |
constexpr duration time_since_epoch() const;
|
| 909 |
|
| 910 |
+
// [time.point.arithmetic], arithmetic
|
| 911 |
+
constexpr time_point& operator+=(const duration& d);
|
| 912 |
+
constexpr time_point& operator-=(const duration& d);
|
| 913 |
|
| 914 |
+
// [time.point.special], special values
|
| 915 |
static constexpr time_point min();
|
| 916 |
static constexpr time_point max();
|
| 917 |
};
|
| 918 |
```
|
| 919 |
|
| 920 |
+
`Clock` shall meet the Clock requirements ([[time.clock.req]]).
|
| 921 |
|
| 922 |
If `Duration` is not an instance of `duration`, the program is
|
| 923 |
ill-formed.
|
| 924 |
|
| 925 |
#### `time_point` constructors <a id="time.point.cons">[[time.point.cons]]</a>
|
|
|
|
| 959 |
*Returns:* `d_`.
|
| 960 |
|
| 961 |
#### `time_point` arithmetic <a id="time.point.arithmetic">[[time.point.arithmetic]]</a>
|
| 962 |
|
| 963 |
``` cpp
|
| 964 |
+
constexpr time_point& operator+=(const duration& d);
|
| 965 |
```
|
| 966 |
|
| 967 |
+
*Effects:* As if by: `d_ += d;`
|
| 968 |
|
| 969 |
*Returns:* `*this`.
|
| 970 |
|
| 971 |
``` cpp
|
| 972 |
+
constexpr time_point& operator-=(const duration& d);
|
| 973 |
```
|
| 974 |
|
| 975 |
+
*Effects:* As if by: `d_ -= d;`
|
| 976 |
|
| 977 |
*Returns:* `*this`.
|
| 978 |
|
| 979 |
#### `time_point` special values <a id="time.point.special">[[time.point.special]]</a>
|
| 980 |
|
|
|
|
| 996 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 997 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 998 |
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 999 |
```
|
| 1000 |
|
| 1001 |
+
*Returns:* *`CT`*`(lhs.time_since_epoch() + rhs)`, where *`CT`* is the
|
| 1002 |
+
type of the return value.
|
| 1003 |
|
| 1004 |
``` cpp
|
| 1005 |
template <class Rep1, class Period1, class Clock, class Duration2>
|
| 1006 |
constexpr time_point<Clock, common_type_t<duration<Rep1, Period1>, Duration2>>
|
| 1007 |
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
| 1013 |
template <class Clock, class Duration1, class Rep2, class Period2>
|
| 1014 |
constexpr time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>
|
| 1015 |
operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
|
| 1016 |
```
|
| 1017 |
|
| 1018 |
+
*Returns:* *`CT`*`(lhs.time_since_epoch() - rhs)`, where *`CT`* is the
|
| 1019 |
+
type of the return value.
|
| 1020 |
|
| 1021 |
``` cpp
|
| 1022 |
template <class Clock, class Duration1, class Duration2>
|
| 1023 |
constexpr common_type_t<Duration1, Duration2>
|
| 1024 |
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
|
|
|
|
| 1028 |
|
| 1029 |
#### `time_point` comparisons <a id="time.point.comparisons">[[time.point.comparisons]]</a>
|
| 1030 |
|
| 1031 |
``` cpp
|
| 1032 |
template <class Clock, class Duration1, class Duration2>
|
| 1033 |
+
constexpr bool operator==(const time_point<Clock, Duration1>& lhs,
|
| 1034 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1035 |
```
|
| 1036 |
|
| 1037 |
*Returns:* `lhs.time_since_epoch() == rhs.time_since_epoch()`.
|
| 1038 |
|
| 1039 |
``` cpp
|
| 1040 |
template <class Clock, class Duration1, class Duration2>
|
| 1041 |
+
constexpr bool operator!=(const time_point<Clock, Duration1>& lhs,
|
| 1042 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1043 |
```
|
| 1044 |
|
| 1045 |
*Returns:* `!(lhs == rhs)`.
|
| 1046 |
|
| 1047 |
``` cpp
|
| 1048 |
template <class Clock, class Duration1, class Duration2>
|
| 1049 |
+
constexpr bool operator<(const time_point<Clock, Duration1>& lhs,
|
| 1050 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1051 |
```
|
| 1052 |
|
| 1053 |
*Returns:* `lhs.time_since_epoch() < rhs.time_since_epoch()`.
|
| 1054 |
|
| 1055 |
``` cpp
|
| 1056 |
template <class Clock, class Duration1, class Duration2>
|
| 1057 |
+
constexpr bool operator<=(const time_point<Clock, Duration1>& lhs,
|
| 1058 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1059 |
```
|
| 1060 |
|
| 1061 |
*Returns:* `!(rhs < lhs)`.
|
| 1062 |
|
| 1063 |
``` cpp
|
| 1064 |
template <class Clock, class Duration1, class Duration2>
|
| 1065 |
+
constexpr bool operator>(const time_point<Clock, Duration1>& lhs,
|
| 1066 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1067 |
```
|
| 1068 |
|
| 1069 |
*Returns:* `rhs < lhs`.
|
| 1070 |
|
| 1071 |
``` cpp
|
| 1072 |
template <class Clock, class Duration1, class Duration2>
|
| 1073 |
+
constexpr bool operator>=(const time_point<Clock, Duration1>& lhs,
|
| 1074 |
+
const time_point<Clock, Duration2>& rhs);
|
| 1075 |
```
|
| 1076 |
|
| 1077 |
*Returns:* `!(lhs < rhs)`.
|
| 1078 |
|
| 1079 |
#### `time_point_cast` <a id="time.point.cast">[[time.point.cast]]</a>
|
|
|
|
| 1083 |
constexpr time_point<Clock, ToDuration>
|
| 1084 |
time_point_cast(const time_point<Clock, Duration>& t);
|
| 1085 |
```
|
| 1086 |
|
| 1087 |
*Remarks:* This function shall not participate in overload resolution
|
| 1088 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 1089 |
|
| 1090 |
*Returns:*
|
| 1091 |
+
|
| 1092 |
+
``` cpp
|
| 1093 |
+
time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()))
|
| 1094 |
+
```
|
| 1095 |
+
|
| 1096 |
+
``` cpp
|
| 1097 |
+
template <class ToDuration, class Clock, class Duration>
|
| 1098 |
+
constexpr time_point<Clock, ToDuration>
|
| 1099 |
+
floor(const time_point<Clock, Duration>& tp);
|
| 1100 |
+
```
|
| 1101 |
+
|
| 1102 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1103 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 1104 |
+
|
| 1105 |
+
*Returns:*
|
| 1106 |
+
`time_point<Clock, ToDuration>(floor<ToDuration>(tp.time_since_epoch()))`.
|
| 1107 |
+
|
| 1108 |
+
``` cpp
|
| 1109 |
+
template <class ToDuration, class Clock, class Duration>
|
| 1110 |
+
constexpr time_point<Clock, ToDuration>
|
| 1111 |
+
ceil(const time_point<Clock, Duration>& tp);
|
| 1112 |
+
```
|
| 1113 |
+
|
| 1114 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1115 |
+
unless `ToDuration` is a specialization of `duration`.
|
| 1116 |
+
|
| 1117 |
+
*Returns:*
|
| 1118 |
+
`time_point<Clock, ToDuration>(ceil<ToDuration>(tp.time_since_epoch()))`.
|
| 1119 |
+
|
| 1120 |
+
``` cpp
|
| 1121 |
+
template <class ToDuration, class Clock, class Duration>
|
| 1122 |
+
constexpr time_point<Clock, ToDuration>
|
| 1123 |
+
round(const time_point<Clock, Duration>& tp);
|
| 1124 |
+
```
|
| 1125 |
+
|
| 1126 |
+
*Remarks:* This function shall not participate in overload resolution
|
| 1127 |
+
unless `ToDuration` is a specialization of `duration`, and
|
| 1128 |
+
`treat_as_floating_point_v<typename ToDuration::rep>` is `false`.
|
| 1129 |
+
|
| 1130 |
+
*Returns:*
|
| 1131 |
+
`time_point<Clock, ToDuration>(round<ToDuration>(tp.time_since_epoch()))`.
|
| 1132 |
|
| 1133 |
### Clocks <a id="time.clock">[[time.clock]]</a>
|
| 1134 |
|
| 1135 |
The types defined in this subclause shall satisfy the `TrivialClock`
|
| 1136 |
requirements ([[time.clock.req]]).
|
|
|
|
| 1141 |
system-wide realtime clock.
|
| 1142 |
|
| 1143 |
``` cpp
|
| 1144 |
class system_clock {
|
| 1145 |
public:
|
| 1146 |
+
using rep = see below;
|
| 1147 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 1148 |
+
using duration = chrono::duration<rep, period>;
|
| 1149 |
+
using time_point = chrono::time_point<system_clock>;
|
| 1150 |
static constexpr bool is_steady = unspecified;
|
| 1151 |
|
| 1152 |
static time_point now() noexcept;
|
| 1153 |
|
| 1154 |
// Map to C API
|
|
|
|
| 1156 |
static time_point from_time_t(time_t t) noexcept;
|
| 1157 |
};
|
| 1158 |
```
|
| 1159 |
|
| 1160 |
``` cpp
|
| 1161 |
+
using system_clock::rep = unspecified;
|
| 1162 |
```
|
| 1163 |
|
| 1164 |
*Requires:*
|
| 1165 |
`system_clock::duration::min() < system_clock::duration::zero()` shall
|
| 1166 |
+
be `true`.
|
| 1167 |
+
|
| 1168 |
+
[*Note 1*: This implies that `rep` is a signed type. — *end note*]
|
| 1169 |
|
| 1170 |
``` cpp
|
| 1171 |
static time_t to_time_t(const time_point& t) noexcept;
|
| 1172 |
```
|
| 1173 |
|
| 1174 |
*Returns:* A `time_t` object that represents the same point in time as
|
| 1175 |
`t` when both values are restricted to the coarser of the precisions of
|
| 1176 |
+
`time_t` and `time_point`. It is *implementation-defined* whether values
|
| 1177 |
are rounded or truncated to the required precision.
|
| 1178 |
|
| 1179 |
``` cpp
|
| 1180 |
static time_point from_time_t(time_t t) noexcept;
|
| 1181 |
```
|
| 1182 |
|
| 1183 |
*Returns:* A `time_point` object that represents the same point in time
|
| 1184 |
as `t` when both values are restricted to the coarser of the precisions
|
| 1185 |
+
of `time_t` and `time_point`. It is *implementation-defined* whether
|
| 1186 |
values are rounded or truncated to the required precision.
|
| 1187 |
|
| 1188 |
#### Class `steady_clock` <a id="time.clock.steady">[[time.clock.steady]]</a>
|
| 1189 |
|
| 1190 |
Objects of class `steady_clock` represent clocks for which values of
|
|
|
|
| 1193 |
That is, the clock may not be adjusted.
|
| 1194 |
|
| 1195 |
``` cpp
|
| 1196 |
class steady_clock {
|
| 1197 |
public:
|
| 1198 |
+
using rep = unspecified;
|
| 1199 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 1200 |
+
using duration = chrono::duration<rep, period>;
|
| 1201 |
+
using time_point = chrono::time_point<unspecified, duration>;
|
| 1202 |
static constexpr bool is_steady = true;
|
| 1203 |
|
| 1204 |
static time_point now() noexcept;
|
| 1205 |
};
|
| 1206 |
```
|
|
|
|
| 1212 |
`system_clock` or `steady_clock`.
|
| 1213 |
|
| 1214 |
``` cpp
|
| 1215 |
class high_resolution_clock {
|
| 1216 |
public:
|
| 1217 |
+
using rep = unspecified;
|
| 1218 |
+
using period = ratio<unspecified, unspecified{}>;
|
| 1219 |
+
using duration = chrono::duration<rep, period>;
|
| 1220 |
+
using time_point = chrono::time_point<unspecified, duration>;
|
| 1221 |
static constexpr bool is_steady = unspecified;
|
| 1222 |
|
| 1223 |
static time_point now() noexcept;
|
| 1224 |
};
|
| 1225 |
```
|
| 1226 |
|
| 1227 |
+
### Header `<ctime>` synopsis <a id="ctime.syn">[[ctime.syn]]</a>
|
| 1228 |
|
| 1229 |
+
``` cpp
|
| 1230 |
+
#define NULL see [support.types.nullptr]
|
| 1231 |
+
#define CLOCKS_PER_SEC see below
|
| 1232 |
+
#define TIME_UTC see below
|
| 1233 |
|
| 1234 |
+
namespace std {
|
| 1235 |
+
using size_t = see [support.types.layout];
|
| 1236 |
+
using clock_t = see below;
|
| 1237 |
+
using time_t = see below;
|
| 1238 |
|
| 1239 |
+
struct timespec;
|
| 1240 |
+
struct tm;
|
| 1241 |
+
|
| 1242 |
+
clock_t clock();
|
| 1243 |
+
double difftime(time_t time1, time_t time0);
|
| 1244 |
+
time_t mktime(struct tm* timeptr);
|
| 1245 |
+
time_t time(time_t* timer);
|
| 1246 |
+
int timespec_get(timespec* ts, int base);
|
| 1247 |
+
char* asctime(const struct tm* timeptr);
|
| 1248 |
+
char* ctime(const time_t* timer);
|
| 1249 |
+
struct tm* gmtime(const time_t* timer);
|
| 1250 |
+
struct tm* localtime(const time_t* timer);
|
| 1251 |
+
size_t strftime(char* s, size_t maxsize, const char* format, const struct tm* timeptr);
|
| 1252 |
+
}
|
| 1253 |
+
```
|
| 1254 |
+
|
| 1255 |
+
The contents of the header `<ctime>` are the same as the C standard
|
| 1256 |
+
library header `<time.h>`. [^3]
|
| 1257 |
+
|
| 1258 |
+
The functions `asctime`, `ctime`, `gmtime`, and `localtime` are not
|
| 1259 |
+
required to avoid data races ([[res.on.data.races]]).
|
| 1260 |
+
|
| 1261 |
+
ISO C 7.27.
|
| 1262 |
|