20 General utilities library [utilities]

20.12 Time utilities [time]

20.12.5 Class template duration [time.duration]

20.12.5.1 duration constructors [time.duration.cons]

template <class Rep2> constexpr explicit duration(const Rep2& r);

Remarks: This constructor shall not participate in overload resolution unless Rep2 is implicitly convertible to rep and

  • treat_as_floating_point<rep>::value is true or

  • treat_as_floating_point<Rep2>::value is false.

Example:

duration<int, milli> d(3);          // OK
duration<int, milli> d(3.5);        // error

 — end example ]

Effects: Constructs an object of type duration.

Postcondition: count() == static_cast<rep>(r).

template <class Rep2, class Period2> constexpr duration(const duration<Rep2, Period2>& d);

Remarks: This constructor shall not participate in overload resolution unless no overflow is induced in the conversion and treat_as_floating_point<rep>::value is true or both ratio_divide<Period2, period>::den is 1 and treat_as_floating_point<Rep2>::value is false. [ Note: This requirement prevents implicit truncation error when converting between integral-based duration types. Such a construction could easily lead to confusion about the value of the duration.  — end note ] [ Example:

duration<int, milli> ms(3);
duration<int, micro> us = ms;       // OK
duration<int, milli> ms2 = us;      // error

 — end example ]

Effects: Constructs an object of type duration, constructing rep_ from
duration_cast<duration>(d).count().