std::chrono::duration<Rep,Period>::duration - cppreference.com (original) (raw)
| constexpr duration() = default; | (1) | (since C++11) |
|---|---|---|
| duration( const duration& ) = default; | (2) | (since C++11) |
| template< class Rep2 > constexpr explicit duration( const Rep2& r ); | (3) | (since C++11) |
| template< class Rep2, class Period2 > constexpr duration( const duration<Rep2, Period2>& d ); | (4) | (since C++11) |
Constructs a new duration from one of several optional data sources.
The default constructor.
The copy constructor.
Constructs a duration with r ticks.
Constructs a duration by converting d to an appropriate period and tick count, as if by std::chrono::duration_cast<duration>(d).count().
- ↑ That is, a duration with an integer tick count cannot be constructed from a floating-point value, but a duration with a floating-point tick count can be constructed from an integer value.
- ↑ That is, either the duration uses floating-point ticks, or
Period2is exactly divisible byPeriod.
[edit] Parameters
| r | - | a tick count |
|---|---|---|
| d | - | a duration to copy from |
[edit] Example
The following code shows several examples (both valid and invalid) of how to construct durations:
[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 2094 | C++11 | for overload (4), std::ratio_divide<Period2, period>::nummight overflow when evaluatingstd::ratio_divide<Period2, period>::den | overload (4) does notparticipate in overloadresolution in this case |
| LWG 3050 | C++11 | convertibility constraint used non-const xvalue | use const lvalues instead |