tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
duration< Rep, Period > Struct Template Reference

Class template etl::chrono::duration represents a time interval. More...

#include <duration.hpp>

Public Types

using period = typename Period::type
 A etl::ratio representing the tick period (i.e. the number of seconds per tick).
 
using rep = Rep
 Rep, an arithmetic type representing the number of ticks.
 

Public Member Functions

constexpr duration () noexcept=default
 Constructs a new duration from one of several optional data sources. The default constructor is defaulted.
 
constexpr duration (duration const &) noexcept=default
 Constructs a new duration from one of several optional data sources. The copy constructor is defaulted (makes a bitwise copy of the tick count).
 
template<typename Rep2, typename Period2>
requires ( treat_as_floating_point_v<rep> or (ratio_divide<Period2, period>::den == 1 and not treat_as_floating_point_v<Rep2>) )
constexpr duration (duration< Rep2, Period2 > const &other) noexcept
 Constructs a duration by converting d to an appropriate period and tick count, as if by duration_cast<duration>(d).count().
 
template<typename Rep2>
requires (is_convertible_v<Rep2, rep> and (treat_as_floating_point_v<rep> or !treat_as_floating_point_v<Rep2>))
constexpr duration (Rep2 const &r) noexcept
 Constructs a duration with r ticks.
 
constexpr auto count () const -> rep
 Returns the number of ticks for this duration.
 
constexpr auto operator%= (duration const &rhs) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
constexpr auto operator%= (rep const &rhs) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
constexpr auto operator*= (rep const &rhs) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
constexpr auto operator+ () const -> etl::common_type_t< duration >
 Implements unary plus and unary minus for the durations.
 
constexpr auto operator++ () -> duration &
 Increments or decrements the number of ticks for this duration. Equivalent to ++_rep; return *this;.
 
constexpr auto operator++ (int) -> duration
 Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep++)
 
constexpr auto operator+= (duration const &d) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
constexpr auto operator- () const -> etl::common_type_t< duration >
 Implements unary plus and unary minus for the durations.
 
constexpr auto operator-- () -> duration &
 Increments or decrements the number of ticks for this duration. Equivalent to –_rep; return *this;.
 
constexpr auto operator-- (int) -> duration
 Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep–);.
 
constexpr auto operator-= (duration const &d) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
constexpr auto operator/= (rep const &rhs) noexcept -> duration &
 Performs compound assignments between two durations with the same period or between a duration and a tick count value.
 
auto operator= (duration const &other) -> duration &=default
 Assigns the contents of one duration to another.
 

Static Public Member Functions

static constexpr auto max () noexcept -> duration
 Returns a duration with the largest possible value.
 
static constexpr auto min () noexcept -> duration
 Returns a duration with the lowest possible value.
 
static constexpr auto zero () noexcept -> duration
 Returns a zero-length duration.
 

Related Symbols

(Note that these are not member symbols.)

template<typename ToDur, typename Rep, typename Period>
constexpr auto duration_cast (duration< Rep, Period > const &duration) noexcept(is_arithmetic_v< Rep > and is_arithmetic_v< typename ToDur::rep >) -> ToDur
 Converts a duration to a duration of different type ToDur.
 

Detailed Description

template<typename Rep, typename Period = etl::ratio<1>>
struct etl::chrono::duration< Rep, Period >

Class template etl::chrono::duration represents a time interval.

It consists of a count of ticks of type Rep and a tick period, where the tick period is a compile-time rational constant representing the number of seconds from one tick to the next. The only data stored in a duration is a tick count of type Rep. If Rep is floating point, then the duration can represent fractions of ticks. Period is included as part of the duration's type, and is only used when converting between different durations.

Member Typedef Documentation

◆ period

template<typename Rep, typename Period = etl::ratio<1>>
using period = typename Period::type

A etl::ratio representing the tick period (i.e. the number of seconds per tick).

◆ rep

template<typename Rep, typename Period = etl::ratio<1>>
using rep = Rep

Rep, an arithmetic type representing the number of ticks.

Constructor & Destructor Documentation

◆ duration() [1/4]

template<typename Rep, typename Period = etl::ratio<1>>
duration ( )
constexprdefaultnoexcept

Constructs a new duration from one of several optional data sources. The default constructor is defaulted.

◆ duration() [2/4]

template<typename Rep, typename Period = etl::ratio<1>>
duration ( duration< Rep, Period > const & )
constexprdefaultnoexcept

Constructs a new duration from one of several optional data sources. The copy constructor is defaulted (makes a bitwise copy of the tick count).

◆ duration() [3/4]

template<typename Rep, typename Period = etl::ratio<1>>
template<typename Rep2>
requires (is_convertible_v<Rep2, rep> and (treat_as_floating_point_v<rep> or !treat_as_floating_point_v<Rep2>))
duration ( Rep2 const & r)
inlineexplicitconstexprnoexcept

Constructs a duration with r ticks.

Note that this constructor only participates in overload resolution if const Rep2& (the argument type) is implicitly convertible to rep (the type of this duration's ticks) and treat_as_floating_point<rep>::value is true, or treat_as_floating_point<Rep2>::value is false.

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

◆ duration() [4/4]

template<typename Rep, typename Period = etl::ratio<1>>
template<typename Rep2, typename Period2>
requires ( treat_as_floating_point_v<rep> or (ratio_divide<Period2, period>::den == 1 and not treat_as_floating_point_v<Rep2>) )
duration ( duration< Rep2, Period2 > const & other)
inlineconstexprnoexcept

Constructs a duration by converting d to an appropriate period and tick count, as if by duration_cast<duration>(d).count().

In order to prevent truncation during conversion, this constructor only participates in overload resolution if computation of the conversion factor (by etl::ratio_divide<Period2, Period>) does not overflow and:

treat_as_floating_point<rep>::value == true

or both:

ratio_divide<Period2, period>::den == 1, and treat_as_floating_point<Rep2>::value == false

That is, either the duration uses floating-point ticks, or Period2 is exactly divisible by period

Member Function Documentation

◆ count()

template<typename Rep, typename Period = etl::ratio<1>>
auto count ( ) const -> rep
inlinenodiscardconstexpr

Returns the number of ticks for this duration.

◆ max()

template<typename Rep, typename Period = etl::ratio<1>>
constexpr auto max ( ) -> duration
inlinestaticnodiscardconstexprnoexcept

Returns a duration with the largest possible value.

◆ min()

template<typename Rep, typename Period = etl::ratio<1>>
constexpr auto min ( ) -> duration
inlinestaticnodiscardconstexprnoexcept

Returns a duration with the lowest possible value.

◆ operator%=() [1/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator%= ( duration< Rep, Period > const & rhs) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator%=() [2/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator%= ( rep const & rhs) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator*=()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator*= ( rep const & rhs) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator+()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator+ ( ) const -> etl::common_type_t<duration>
inlinenodiscardconstexpr

Implements unary plus and unary minus for the durations.

◆ operator++() [1/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator++ ( ) -> duration&
inlineconstexpr

Increments or decrements the number of ticks for this duration. Equivalent to ++_rep; return *this;.

◆ operator++() [2/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator++ ( int ) -> duration
inlineconstexpr

Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep++)

◆ operator+=()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator+= ( duration< Rep, Period > const & d) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator-()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator- ( ) const -> etl::common_type_t<duration>
inlinenodiscardconstexpr

Implements unary plus and unary minus for the durations.

◆ operator--() [1/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator-- ( ) -> duration&
inlineconstexpr

Increments or decrements the number of ticks for this duration. Equivalent to –_rep; return *this;.

◆ operator--() [2/2]

template<typename Rep, typename Period = etl::ratio<1>>
auto operator-- ( int ) -> duration
inlineconstexpr

Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep–);.

◆ operator-=()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator-= ( duration< Rep, Period > const & d) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator/=()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator/= ( rep const & rhs) -> duration&
inlineconstexprnoexcept

Performs compound assignments between two durations with the same period or between a duration and a tick count value.

◆ operator=()

template<typename Rep, typename Period = etl::ratio<1>>
auto operator= ( duration< Rep, Period > const & other) -> duration &=default
default

Assigns the contents of one duration to another.

◆ zero()

template<typename Rep, typename Period = etl::ratio<1>>
constexpr auto zero ( ) -> duration
inlinestaticnodiscardconstexprnoexcept

Returns a zero-length duration.


The documentation for this struct was generated from the following files: