I/O chrono help functions

Overview

Defines some helpers for chrono types. More…

// global functions

template <DurationType durantion_t>
INLINE std::istream& operator >> (
    std::istream& is,
    durantion_t& duration
);

INLINE std::ostream& operator << (
    std::ostream& os,
    const std::chrono::duration<double>& dur
);

Detailed Documentation

Defines some helpers for chrono types.

Todo These functions may not be necessary for C++23, since streaming operators for chrono types are defined there.

Global Functions

template <DurationType durantion_t>
INLINE std::istream& operator >> (
    std::istream& is,
    durantion_t& duration
)

Input stream operator for std::chrono durations.

Until C++20, we have no operator>> for reading std::chrono. So, the following definition is only for reading seconds. We first read the integer representation of a second, then convert it to the duration.

Parameters:

durantion_t

a chrono::duration type.

is

the input stream.

duration

the duration

Returns:

the input stream.

INLINE std::ostream& operator << (
    std::ostream& os,
    const std::chrono::duration<double>& dur
)

Output stream operator for chrono durations (and seconds) for Clang/libc.

To the date, libc (clang) has no support to stream chrono objects. This is a working around only for seconds.

Todo Remove this when clang/libc get the support.

Parameters:

os

the output operator.

dur

the duration.

Returns:

the output operator.