3#ifndef TETL_CHRONO_DURATION_HPP
4#define TETL_CHRONO_DURATION_HPP
30template <
typename Rep,
typename Period = etl::ratio<1>>
37 using period =
typename Period::type;
59 template <typename Rep2>
61 constexpr explicit
duration(Rep2 const& r) noexcept
83 template <
typename Rep2,
typename Period2>
97 [[nodiscard]]
constexpr auto count() const ->
rep {
return _rep; }
216template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
219 static constexpr auto num =
gcd(Period1::num, Period2::num);
220 static constexpr auto den =
lcm(Period1::den, Period2::den);
237template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
242 using CR =
typename CD::rep;
243 return CD(
static_cast<CR
>(CD(lhs).
count() + CD(rhs).
count()));
254template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
259 using CR =
typename CD::rep;
260 return CD(
static_cast<CR
>(CD(lhs).
count() - CD(rhs).
count()));
271template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
276 return CD(lhs).
count() / CD(rhs).count();
287template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
292 using CR =
typename CD::rep;
293 return CD(
static_cast<CR
>(CD(lhs).
count() % CD(rhs).
count()));
298template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
302 return common_t(lhs).
count() == common_t(rhs).count();
307template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
310 return !(lhs == rhs);
315template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
319 return common_t(lhs).
count() < common_t(rhs).count();
324template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
332template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
340template <
typename Rep1,
typename Period1,
typename Rep2,
typename Period2>
484using namespace etl::literals::chrono_literals;
constexpr auto count(InputIt first, InputIt last, T const &value) -> typename iterator_traits< InputIt >::difference_type
Returns the number of elements in the range [first, last) satisfying specific criteria....
Definition count.hpp:21
constexpr bool treat_as_floating_point_v
Definition treat_as_floating_point.hpp:24
constexpr auto gcd(M m, N n) noexcept -> etl::common_type_t< M, N >
Computes the greatest common divisor of the integers m and n.
Definition gcd.hpp:16
constexpr auto lcm(M m, N n) -> common_type_t< M, N >
Computes the least common multiple of the integers m and n.
Definition lcm.hpp:20
duration< int_least64_t, micro > microseconds
Signed integer type of at least 55 bits.
Definition duration.hpp:350
constexpr auto operator%(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> common_type_t< duration< Rep1, Period1 >, duration< Rep2, Period2 > >
Performs basic arithmetic operations between two durations or between a duration and a tick count.
Definition duration.hpp:288
constexpr auto operator<(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Compares lhs to rhs, i.e. compares the number of ticks for the type common to...
Definition duration.hpp:316
constexpr auto operator+(day const &d, days const &ds) noexcept -> day
Definition day.hpp:92
constexpr auto operator>(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Compares lhs to rhs, i.e. compares the number of ticks for the type common to...
Definition duration.hpp:333
duration< int_least32_t, ratio< 31556952 > > months
Signed integer type of at least 20 bits.
Definition duration.hpp:371
duration< int_least64_t, milli > milliseconds
Signed integer type of at least 45 bits.
Definition duration.hpp:353
constexpr auto operator==(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Checks if lhs and rhs are equal, i.e. the number of ticks for the type common...
Definition duration.hpp:299
duration< int_least32_t, ratio< 86400 > > days
Signed integer type of at least 25 bits.
Definition duration.hpp:365
duration< int_least32_t, ratio< 604800 > > weeks
Signed integer type of at least 22 bits.
Definition duration.hpp:368
constexpr auto operator!=(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Checks if lhs and rhs are equal, i.e. the number of ticks for the type common...
Definition duration.hpp:308
duration< int_least32_t, ratio< 60 > > minutes
Signed integer type of at least 29 bits.
Definition duration.hpp:359
constexpr auto operator/(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> common_type_t< Rep1, Rep2 >
Performs basic arithmetic operations between two durations or between a duration and a tick count.
Definition duration.hpp:272
duration< int_least32_t, ratio< 2629746 > > years
Signed integer type of at least 17 bits.
Definition duration.hpp:374
constexpr auto operator<=(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Compares lhs to rhs, i.e. compares the number of ticks for the type common to...
Definition duration.hpp:325
duration< int_least64_t, nano > nanoseconds
Signed integer type of at least 64 bits.
Definition duration.hpp:347
constexpr auto operator-(day const &d, days const &ds) noexcept -> day
Definition day.hpp:102
duration< int_least64_t > seconds
Signed integer type of at least 35 bits.
Definition duration.hpp:356
constexpr auto operator>=(duration< Rep1, Period1 > const &lhs, duration< Rep2, Period2 > const &rhs) -> bool
Compares two durations. Compares lhs to rhs, i.e. compares the number of ticks for the type common to...
Definition duration.hpp:341
duration< int_least32_t, ratio< 3600 > > hours
Signed integer type of at least 23 bits.
Definition duration.hpp:362
Definition adjacent_find.hpp:8
typename common_type< T... >::type common_type_t
Definition common_type.hpp:50
constexpr bool is_convertible_v
Definition is_convertible.hpp:46
static constexpr auto max() -> Rep
Returns the special duration value max.
Definition duration_values.hpp:28
static constexpr auto min() -> Rep
Returns the smallest possible representation.
Definition duration_values.hpp:25
static constexpr auto zero() -> Rep
Returns a zero-length representation.
Definition duration_values.hpp:22
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:31
static constexpr auto min() noexcept -> duration
Returns a duration with the lowest possible value.
Definition duration.hpp:106
constexpr auto count() const -> rep
Returns the number of ticks for this duration.
Definition duration.hpp:97
typename Period::type period
A etl::ratio representing the tick period (i.e. the number of seconds per tick).
Definition duration.hpp:37
constexpr auto operator--() -> duration &
Increments or decrements the number of ticks for this duration. Equivalent to –_rep; return *this;.
Definition duration.hpp:143
constexpr auto operator/=(rep const &rhs) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:179
constexpr auto operator-=(duration const &d) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:163
constexpr auto operator+=(duration const &d) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:155
constexpr auto operator+() const -> etl::common_type_t< duration >
Implements unary plus and unary minus for the durations.
Definition duration.hpp:118
constexpr auto operator++(int) -> duration
Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep++)
Definition duration.hpp:139
Rep rep
Rep, an arithmetic type representing the number of ticks.
Definition duration.hpp:33
constexpr auto operator%=(rep const &rhs) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:187
auto operator=(duration const &other) -> duration &=default
Assigns the contents of one duration to another.
static constexpr auto zero() noexcept -> duration
Returns a zero-length duration.
Definition duration.hpp:100
constexpr auto operator-() const -> etl::common_type_t< duration >
Implements unary plus and unary minus for the durations.
Definition duration.hpp:124
constexpr auto operator*=(rep const &rhs) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:171
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...
Definition duration.hpp:88
static constexpr auto max() noexcept -> duration
Returns a duration with the largest possible value.
Definition duration.hpp:112
constexpr auto operator--(int) -> duration
Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep–);...
Definition duration.hpp:151
constexpr auto operator%=(duration const &rhs) noexcept -> duration &
Performs compound assignments between two durations with the same period or between a duration and a ...
Definition duration.hpp:195
constexpr auto operator++() -> duration &
Increments or decrements the number of ticks for this duration. Equivalent to ++_rep; return *this;.
Definition duration.hpp:131
constexpr duration() noexcept=default
Constructs a new duration from one of several optional data sources. The default constructor is defau...
chrono::duration< common_type_t< Rep1, Rep2 >, ratio< num, den > > type
Definition duration.hpp:223
Determines the common type among all types T..., that is the type all T... can be implicitly converte...
Definition common_type.hpp:18
The typename template provides compile-time rational arithmetic support. Each instantiation of this t...
Definition ratio.hpp:21
static constexpr intmax_t den
Definition ratio.hpp:23
static constexpr intmax_t num
Definition ratio.hpp:22