[time.traits] (original) (raw)

30 Time library [time]

30.4.1 treat_as_floating_point [time.traits.is.fp]

template<class Rep> struct treat_as_floating_point : is_floating_point<Rep> { };

The duration template uses the treat_as_floating_point trait to help determine if a duration object can be converted to anotherduration with a different tick period.

Iftreat_as_floating_point_v<Rep> is true, then implicit conversions are allowed among durations.

Otherwise, the implicit convertibility depends on the tick periods of the durations.

[Note 1:

The intention of this trait is to indicate whether a given class behaves like a floating-point type, and thus allows division of one value by another with acceptable loss of precision.

Iftreat_as_floating_point_v<Rep> is false, Rep will be treated as if it behaved like an integral type for the purpose of these conversions.

— _end note_]

30.4.2 duration_values [time.traits.duration.values]

template<class Rep> struct duration_values { public: static constexpr Rep zero() noexcept;static constexpr Rep min() noexcept;static constexpr Rep max() noexcept;};

The duration template uses the duration_values trait to construct special values of the duration's representation (Rep).

This is done because the representation can be a class type with behavior that requires some other implementation to return these special values.

In that case, the author of that class type should specialize duration_values to return the indicated values.

static constexpr Rep zero() noexcept;

Returns: Rep(0).

[Note 1:

Rep(0) is specified instead ofRep() because Rep() can have some other meaning, such as an uninitialized value.

— _end note_]

Remarks: The value returned shall be the additive identity.

static constexpr Rep min() noexcept;

Returns: numeric_limits<Rep>​::​lowest().

Remarks: The value returned shall compare less than or equal to zero().

static constexpr Rep max() noexcept;

Returns: numeric_limits<Rep>​::​max().

Remarks: The value returned shall compare greater than zero().

30.4.3 Specializations of common_type [time.traits.specializations]

template<class Rep1, class Period1, class Rep2, class Period2> struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> { using type = chrono::duration<common_type_t<Rep1, Rep2>, _see below_>;};

The period of the duration indicated by this specialization ofcommon_type is the greatest common divisor of Period1 andPeriod2.

[Note 1:

This can be computed by forming a ratio of the greatest common divisor of Period1​::​num and Period2​::​num and the least common multiple of Period1​::​den and Period2​::​den.

— _end note_]

[Note 2:

The typedef name type is a synonym for theduration with the largest tick period possible where bothduration arguments will convert to it without requiring a division operation.

The representation of this type is intended to be able to hold any value resulting from this conversion with no truncation error, although floating-point durations can have round-off errors.

— _end note_]

template<class Clock, class Duration1, class Duration2> struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>> { using type = chrono::time_point<Clock, common_type_t<Duration1, Duration2>>;};

The common type of two time_point types is a time_point with the same clock as the two types and the common type of their two durations.

30.4.4 Class template is_clock [time.traits.is.clock]

template<class T> struct is_clock;

For the purposes of the specification of this trait, the extent to which an implementation determines that a type cannot meet the Cpp17Clock requirements is unspecified, except that as a minimum a type T shall not qualify as a Cpp17Clockunless it meets all of the following conditions:

The behavior of a program that adds specializations for is_clock is undefined.