Files
2025-10-25 03:02:53 +03:00

1.9 KiB
Raw Permalink Blame History

[time.duration.cons]

30 Time library [time]

30.5 Class template duration [time.duration]

30.5.2 Constructors [time.duration.cons]

🔗

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

1

#

Constraints: is_convertible_v<const Rep2&, rep> is true and

treat_as_floating_point_v is true or

treat_as_floating_point_v is false.

[Example 1: duration<int, milli> d(3); // OK duration<int, milli> d2(3.5); // error — end example]

2

#

Effects: Initializes rep_ with r.

🔗

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

3

#

Constraints: No overflow is induced in the conversion andtreat_as_floating_point_v is true or bothratio_divide<Period2, period>::den is 1 andtreat_as_floating_point_v is false.

[Note 1:

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 2: duration<int, milli> ms(3); duration<int, micro> us = ms; // OK duration<int, milli> ms2 = us; // error — end example]

4

#

Effects: Initializes rep_ with duration_cast(d).count().