31#ifndef ETL_IN_CHRONO_H
32 #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
36#include "../../static_assert.h"
46 namespace private_chrono
49 template <
intmax_t Value1,
intmax_t Value2>
52 static ETL_CONSTANT intmax_t value = gcd<Value2, Value1 % Value2>::value;
55 template <
intmax_t Value1>
58 static ETL_CONSTANT intmax_t value = Value1;
62 template <
intmax_t Value1,
intmax_t Value2>
65 static ETL_CONSTANT intmax_t value = (Value1 / gcd<Value1, Value2>::value) * Value2;
72 template <
typename TRep>
77 static ETL_CONSTEXPR TRep zero() ETL_NOEXCEPT
84 static ETL_CONSTEXPR14 TRep min() ETL_NOEXCEPT
91 static ETL_CONSTEXPR14 TRep max() ETL_NOEXCEPT
97 template <
typename TRep,
typename TPeriod>
100 template <
typename TToDuration,
typename TRep,
typename TPeriod>
106 template <
typename TRep,
typename TPeriod = etl::ratio<1> >
112 using period =
typename TPeriod::type;
115 ETL_CONSTEXPR duration() ETL_NOEXCEPT
127 template <
typename TRep2>
128 ETL_CONSTEXPR14
explicit duration(
const TRep2& value_) ETL_NOEXCEPT
129 : value(
static_cast<TRep
>(value_))
134 template <typename TRep2, typename TPeriod2, typename etl::enable_if<etl::ratio_divide<TPeriod2, TPeriod>::den == 1,
int>
::type = 0>
145 value = other.count();
151 template <
typename TRep2,
typename TPeriod2>
161 ETL_CONSTEXPR14 TRep count()
const ETL_NOEXCEPT
167 ETL_CONSTEXPR14 etl::common_type_t<duration> operator +()
const ETL_NOEXCEPT
169 return etl::common_type_t<duration>(*
this);
173 ETL_CONSTEXPR14 etl::common_type_t<duration> operator -()
const ETL_NOEXCEPT
175 return etl::common_type_t<duration>(-value);
207 ETL_CONSTEXPR14 duration& operator ++() ETL_NOEXCEPT
215 ETL_CONSTEXPR14 duration operator ++(
int) ETL_NOEXCEPT
217 duration temp(*
this);
224 ETL_CONSTEXPR14 duration& operator --() ETL_NOEXCEPT
232 ETL_CONSTEXPR14 duration operator --(
int) ETL_NOEXCEPT
234 duration temp(*
this);
241 ETL_CONSTEXPR14 duration& operator +=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
249 ETL_CONSTEXPR14 duration& operator -=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
257 ETL_CONSTEXPR14 duration& operator *=(
const TRep& r) ETL_NOEXCEPT
265 ETL_CONSTEXPR14 duration& operator /=(
const TRep& r) ETL_NOEXCEPT
273 ETL_CONSTEXPR14 duration& operator %=(
const TRep& r) ETL_NOEXCEPT
281 ETL_CONSTEXPR14 duration& operator %=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
294 template <
typename TRep2,
typename TPeriod2>
295 ETL_CONSTEXPR14
int compare(
const duration<TRep2, TPeriod2>& other)
const ETL_NOEXCEPT
303 if (lhs_converted.count() < rhs_converted.count())
return -1;
304 if (lhs_converted.count() > rhs_converted.count())
return 1;
317#if (ETL_USING_64BIT_TYPES)
338 template <
typename TToDuration,
typename TRep,
typename TPeriod>
341 using from_rep = TRep ;
342 using from_period = TPeriod ;
344 using to_rep =
typename TToDuration::rep;
345 using to_period =
typename TToDuration::period;
347 using ratio_divide_t =
typename etl::ratio_divide<from_period, to_period>;
348 using common_t =
typename etl::common_type<from_rep, to_rep, intmax_t>::type;
350 common_t ct_count =
static_cast<common_t
>(d.count());
351 common_t ct_num =
static_cast<common_t
>(ratio_divide_t::type::num);
352 common_t ct_den =
static_cast<common_t
>(ratio_divide_t::type::den);
354 if ETL_IF_CONSTEXPR((from_period::num == to_period::num) && (from_period::den == to_period::den))
356 return TToDuration(
static_cast<to_rep
>(d.count()));
358 else if ETL_IF_CONSTEXPR(ratio_divide_t::num == 1)
360 return TToDuration(
static_cast<to_rep
>(ct_count / ct_den));
362 else if ETL_IF_CONSTEXPR(ratio_divide_t::den == 1)
364 return TToDuration(
static_cast<to_rep
>(ct_count * ct_num));
368 return TToDuration(
static_cast<to_rep
>((ct_count * ct_num) / ct_den));
376#if ETL_USING_8BIT_TYPES
377 template <
typename TRep,
typename TPeriod>
378 struct hash<
etl::chrono::duration<TRep, TPeriod> >
382 uint8_t buffer[
sizeof(TRep) +
sizeof(intmax_t) +
sizeof(intmax_t)];
384 TRep value = d.count();
385 intmax_t num = TPeriod::num;
386 intmax_t den = TPeriod::den;
388 memcpy(buffer, &value,
sizeof(TRep));
389 memcpy(buffer +
sizeof(TRep), &num,
sizeof(intmax_t));
390 memcpy(buffer +
sizeof(TRep) +
sizeof(intmax_t), &den,
sizeof(intmax_t));
392 return etl::private_hash::generic_hash<size_t>(buffer, buffer +
sizeof(TRep) +
sizeof(intmax_t) +
sizeof(intmax_t));
400 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
405 using value_type =
typename etl::common_type<TRep1, TRep2>::type ;
407 etl::chrono::private_chrono::lcm<TPeriod1::den, TPeriod2::den>::value>;
417 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
426 return l.count() == r.count();
432 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
436 return !(lhs == rhs);
442 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
451 return l.count() < r.count();
457 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
467 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
477 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
488 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
497 return (l.count() <=> r.count());
504 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
505 ETL_CONSTEXPR14
typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type
517 return common_duration(lhs_converted.count() + rhs_converted.count());
523 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
536 return common_duration(lhs_converted.count() - rhs_converted.count());
542 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
546 const TRep2& rhs) ETL_NOEXCEPT
548 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
552 return result_duration(
static_cast<common_rep
>(lhs.count()) *
static_cast<common_rep
>(rhs));
558 template <
typename TRep1,
typename TRep2,
typename TPeriod2>
563 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
567 return result_duration(
static_cast<common_rep
>(rhs.count()) *
static_cast<common_rep
>(lhs));
573 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
577 const TRep2& rhs) ETL_NOEXCEPT
579 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
583 return result_duration(
static_cast<common_rep
>(lhs.count()) /
static_cast<common_rep
>(rhs));
589 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
590 ETL_CONSTEXPR14
typename etl::common_type<TRep1, TRep2>::type
600 return typename etl::common_type<TRep1, TRep2>::type(lhs_converted.count() / rhs_converted.count());
606 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
610 const TRep2& rhs) ETL_NOEXCEPT
612 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
616 return common_dur(
static_cast<common_rep
>(lhs.count()) % rhs);
622 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
634 return common_duration(lhs_converted.count() % rhs_converted.count());
640 template <
typename TToDuration,
typename TRep,
typename TPeriod>
658 template <
typename TToDuration,
typename TRep,
typename TPeriod>
677 template <
typename TToDuration,
typename TRep,
typename TPeriod>
686 auto lower_diff = d - lower;
687 auto upper_diff = upper - d;
689 if ((lower_diff < upper_diff) ||
690 ((lower_diff == upper_diff) &&
704 template<class TRep, class TPeriod, typename = etl::enable_if_t<etl::numeric_limits<TRep>::is_signed>>
707 return d.count() >= 0 ? +d : -d;
711#if ETL_HAS_CHRONO_LITERALS_DURATION
714 inline namespace literals
716 inline namespace chrono_literals
721#if ETL_USING_VERBOSE_CHRONO_LITERALS
722 inline ETL_CONSTEXPR14 etl::chrono::hours
operator ""_hours(
unsigned long long h) ETL_NOEXCEPT
724 inline ETL_CONSTEXPR14 etl::chrono::hours
operator ""_h(
unsigned long long h) ETL_NOEXCEPT
727 return etl::chrono::hours(
static_cast<etl::chrono::hours::rep
>(h));
733#if ETL_USING_VERBOSE_CHRONO_LITERALS
745#if ETL_USING_VERBOSE_CHRONO_LITERALS
746 inline ETL_CONSTEXPR14 etl::chrono::minutes
operator ""_minutes(
unsigned long long m) ETL_NOEXCEPT
748 inline ETL_CONSTEXPR14 etl::chrono::minutes
operator ""_min(
unsigned long long m) ETL_NOEXCEPT
751 return etl::chrono::minutes(
static_cast<etl::chrono::minutes::rep
>(m));
757#if ETL_USING_VERBOSE_CHRONO_LITERALS
769#if ETL_USING_VERBOSE_CHRONO_LITERALS
770 inline ETL_CONSTEXPR14 etl::chrono::seconds
operator ""_seconds(
unsigned long long s) ETL_NOEXCEPT
772 inline ETL_CONSTEXPR14 etl::chrono::seconds
operator ""_s(
unsigned long long s) ETL_NOEXCEPT
775 return etl::chrono::seconds(
static_cast<etl::chrono::seconds::rep
>(s));
781#if ETL_USING_VERBOSE_CHRONO_LITERALS
793#if ETL_USING_VERBOSE_CHRONO_LITERALS
794 inline ETL_CONSTEXPR14 etl::chrono::milliseconds
operator ""_milliseconds(
unsigned long long s) ETL_NOEXCEPT
796 inline ETL_CONSTEXPR14 etl::chrono::milliseconds
operator ""_ms(
unsigned long long s) ETL_NOEXCEPT
799 return etl::chrono::milliseconds(
static_cast<etl::chrono::milliseconds::rep
>(s));
805#if ETL_USING_VERBOSE_CHRONO_LITERALS
817#if ETL_USING_VERBOSE_CHRONO_LITERALS
818 inline ETL_CONSTEXPR14 etl::chrono::microseconds
operator ""_microseconds(
unsigned long long s) ETL_NOEXCEPT
820 inline ETL_CONSTEXPR14 etl::chrono::microseconds
operator ""_us(
unsigned long long s) ETL_NOEXCEPT
823 return etl::chrono::microseconds(
static_cast<etl::chrono::microseconds::rep
>(s));
829#if ETL_USING_VERBOSE_CHRONO_LITERALS
841#if ETL_USING_VERBOSE_CHRONO_LITERALS
853#if ETL_USING_VERBOSE_CHRONO_LITERALS
duration
Definition duration.h:108
ETL_CONSTEXPR14 int compare(const duration< TRep2, TPeriod2 > &other) const ETL_NOEXCEPT
Definition duration.h:295
etl::chrono::duration< int64_t, etl::nano > nanoseconds
Duration types.
Definition duration.h:318
ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
duration_cast
Definition duration.h:339
ETL_CONSTEXPR etl::enable_if< etl::is_integral< T >::value, bool >::type is_even(T value)
Definition binary.h:2209
enable_if
Definition type_traits_generator.h:1254
is_floating_point
Definition type_traits_generator.h:1094
bitset_ext
Definition absolute.h:39
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type ceil(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Rounds up a duration to the nearest higher precision.
Definition duration.h:661
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:672
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1190
ETL_CONSTEXPR14 enable_if<!etl::is_specialization< TRep2, etl::chrono::duration >::value, etl::chrono::duration< typenameetl::common_type< TRep1, TRep2 >::type, TPeriod1 > >::type operator/(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator /.
Definition duration.h:576
ETL_CONSTEXPR14 etl::chrono::duration< typename etl::common_type< TRep1, TRep2 >::type, TPeriod1 > operator%(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator %.
Definition duration.h:609
ETL_CONSTEXPR14 etl::chrono::duration< TRep, TPeriod > abs(etl::chrono::duration< TRep, TPeriod > d) ETL_NOEXCEPT
Returns the absolute value of a duration.
Definition duration.h:705
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1202
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type floor(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Rounds down a duration to the nearest lower precision.
Definition duration.h:643
ETL_CONSTEXPR14 etl::enable_if< etl::is_specialization< TToDuration, etl::chrono::duration >::value, TToDuration >::type round(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
Definition duration.h:680
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
ETL_CONSTEXPR14 enable_if<!etl::is_specialization< TRep2, etl::chrono::duration >::value, etl::chrono::duration< typenameetl::common_type< TRep1, TRep2 >::type, TPeriod1 > >::type operator*(const etl::chrono::duration< TRep1, TPeriod1 > &lhs, const TRep2 &rhs) ETL_NOEXCEPT
Operator *.
Definition duration.h:545
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:659
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1163
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1178
duration_values
Definition duration.h:74
ratio
Definition ratio.h:53