31#ifndef ETL_IN_CHRONO_H
32 #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H
37#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>
138 ETL_STATIC_ASSERT(!(etl::is_integral<TRep>::value && etl::is_floating_point<TRep2>::value),
139 "Cannot convert duration from floating point to integral");
145 value = other.count();
151 template <
typename TRep2,
typename TPeriod2>
160 ETL_CONSTEXPR14 TRep count()
const ETL_NOEXCEPT
166 ETL_CONSTEXPR14 etl::common_type_t<duration> operator+()
const ETL_NOEXCEPT
168 return etl::common_type_t<duration>(*
this);
172 ETL_CONSTEXPR14 etl::common_type_t<duration> operator-()
const ETL_NOEXCEPT
174 return etl::common_type_t<duration>(-value);
205 ETL_CONSTEXPR14 duration& operator++() ETL_NOEXCEPT
213 ETL_CONSTEXPR14 duration operator++(
int) ETL_NOEXCEPT
215 duration temp(*
this);
222 ETL_CONSTEXPR14 duration& operator--() ETL_NOEXCEPT
230 ETL_CONSTEXPR14 duration operator--(
int) ETL_NOEXCEPT
232 duration temp(*
this);
239 ETL_CONSTEXPR14 duration& operator+=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
247 ETL_CONSTEXPR14 duration& operator-=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
255 ETL_CONSTEXPR14 duration& operator*=(
const TRep& r) ETL_NOEXCEPT
263 ETL_CONSTEXPR14 duration& operator/=(
const TRep& r) ETL_NOEXCEPT
271 ETL_CONSTEXPR14 duration& operator%=(
const TRep& r) ETL_NOEXCEPT
279 ETL_CONSTEXPR14 duration& operator%=(
const duration<TRep, TPeriod>& d) ETL_NOEXCEPT
292 template <
typename TRep2,
typename TPeriod2>
293 ETL_CONSTEXPR14
int compare(
const duration<TRep2, TPeriod2>& other)
const ETL_NOEXCEPT
301 if (lhs_converted.count() < rhs_converted.count())
303 if (lhs_converted.count() > rhs_converted.count())
317#if (ETL_USING_64BIT_TYPES)
318 #if (INT_MAX >= INT32_MAX)
325 #if (INT_MAX >= INT32_MAX)
342 template <
typename TToDuration,
typename TRep,
typename TPeriod>
345 using from_rep = TRep;
346 using from_period = TPeriod;
348 using to_rep =
typename TToDuration::rep;
349 using to_period =
typename TToDuration::period;
351 using ratio_divide_t =
typename etl::ratio_divide<from_period, to_period>;
352 using common_t =
typename etl::common_type<from_rep, to_rep, intmax_t>::type;
354 common_t ct_count =
static_cast<common_t
>(d.count());
355 common_t ct_num =
static_cast<common_t
>(ratio_divide_t::type::num);
356 common_t ct_den =
static_cast<common_t
>(ratio_divide_t::type::den);
358 if ETL_IF_CONSTEXPR ((from_period::num == to_period::num) && (from_period::den == to_period::den))
360 return TToDuration(
static_cast<to_rep
>(d.count()));
362 else if ETL_IF_CONSTEXPR (ratio_divide_t::num == 1)
364 return TToDuration(
static_cast<to_rep
>(ct_count / ct_den));
366 else if ETL_IF_CONSTEXPR (ratio_divide_t::den == 1)
368 return TToDuration(
static_cast<to_rep
>(ct_count * ct_num));
372 return TToDuration(
static_cast<to_rep
>((ct_count * ct_num) / ct_den));
380#if ETL_USING_8BIT_TYPES
381 template <
typename TRep,
typename TPeriod>
382 struct hash<
etl::chrono::duration<TRep, TPeriod> >
386 uint8_t buffer[
sizeof(TRep) +
sizeof(intmax_t) +
sizeof(intmax_t)];
388 TRep value = d.count();
389 intmax_t num = TPeriod::num;
390 intmax_t den = TPeriod::den;
392 memcpy(buffer, &value,
sizeof(TRep));
393 memcpy(buffer +
sizeof(TRep), &num,
sizeof(intmax_t));
394 memcpy(buffer +
sizeof(TRep) +
sizeof(intmax_t), &den,
sizeof(intmax_t));
396 return etl::private_hash::generic_hash<size_t>(buffer, buffer +
sizeof(TRep) +
sizeof(intmax_t) +
sizeof(intmax_t));
404 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
409 using value_type =
typename etl::common_type<TRep1, TRep2>::type;
411 etl::chrono::private_chrono::lcm<TPeriod1::den, TPeriod2::den>::value>;
421 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
429 return l.count() == r.count();
435 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
438 return !(lhs == rhs);
444 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
452 return l.count() < r.count();
458 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
467 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
476 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
486 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
495 return (l.count() <=> r.count());
502 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
503 ETL_CONSTEXPR14
typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2> >::type
514 return common_duration(lhs_converted.count() + rhs_converted.count());
520 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
532 return common_duration(lhs_converted.count() - rhs_converted.count());
538 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
539 ETL_CONSTEXPR14
typename enable_if< !etl::is_specialization<TRep2, etl::chrono::duration>::value,
543 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
547 return result_duration(
static_cast<common_rep
>(lhs.count()) *
static_cast<common_rep
>(rhs));
553 template <
typename TRep1,
typename TRep2,
typename TPeriod2>
557 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
561 return result_duration(
static_cast<common_rep
>(rhs.count()) *
static_cast<common_rep
>(lhs));
567 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
568 ETL_CONSTEXPR14
typename enable_if< !etl::is_specialization<TRep2, etl::chrono::duration>::value,
572 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
576 return result_duration(
static_cast<common_rep
>(lhs.count()) /
static_cast<common_rep
>(rhs));
582 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
592 return typename etl::common_type<TRep1, TRep2>::type(lhs_converted.count() / rhs_converted.count());
598 template <
typename TRep1,
typename TPeriod1,
typename TRep2>
602 using common_rep =
typename etl::common_type<TRep1, TRep2>::type;
606 return common_dur(
static_cast<common_rep
>(lhs.count()) % rhs);
612 template <
typename TRep1,
typename TPeriod1,
typename TRep2,
typename TPeriod2>
622 return common_duration(lhs_converted.count() % rhs_converted.count());
628 template <
typename TToDuration,
typename TRep,
typename TPeriod>
629 ETL_CONSTEXPR14
typename etl::enable_if< etl::is_specialization<TToDuration, etl::chrono::duration>::value, TToDuration>
::type
645 template <
typename TToDuration,
typename TRep,
typename TPeriod>
646 ETL_CONSTEXPR14
typename etl::enable_if< etl::is_specialization<TToDuration, etl::chrono::duration>::value, TToDuration>
::type
663 template <
typename TToDuration,
typename TRep,
typename TPeriod>
664 ETL_CONSTEXPR14
typename etl::enable_if< etl::is_specialization<TToDuration, etl::chrono::duration>::value, TToDuration>
::type
671 auto lower_diff = d - lower;
672 auto upper_diff = upper - d;
674 if ((lower_diff < upper_diff) || ((lower_diff == upper_diff) &&
etl::is_even(lower.count())))
687 template <class TRep, class TPeriod, typename = etl::enable_if_t<etl::numeric_limits<TRep>::is_signed>>
690 return d.count() >= 0 ? +d : -d;
694#if ETL_HAS_CHRONO_LITERALS_DURATION
697 inline namespace literals
699 inline namespace chrono_literals
704 #if ETL_USING_VERBOSE_CHRONO_LITERALS
705 inline ETL_CONSTEXPR14 etl::chrono::hours
operator""_hours(
unsigned long long h) ETL_NOEXCEPT
707 inline ETL_CONSTEXPR14 etl::chrono::hours
operator""_h(
unsigned long long h) ETL_NOEXCEPT
710 return etl::chrono::hours(
static_cast<etl::chrono::hours::rep
>(h));
716 #if ETL_USING_VERBOSE_CHRONO_LITERALS
728 #if ETL_USING_VERBOSE_CHRONO_LITERALS
729 inline ETL_CONSTEXPR14 etl::chrono::minutes
operator""_minutes(
unsigned long long m) ETL_NOEXCEPT
731 inline ETL_CONSTEXPR14 etl::chrono::minutes
operator""_min(
unsigned long long m) ETL_NOEXCEPT
734 return etl::chrono::minutes(
static_cast<etl::chrono::minutes::rep
>(m));
740 #if ETL_USING_VERBOSE_CHRONO_LITERALS
752 #if ETL_USING_VERBOSE_CHRONO_LITERALS
753 inline ETL_CONSTEXPR14 etl::chrono::seconds
operator""_seconds(
unsigned long long s) ETL_NOEXCEPT
755 inline ETL_CONSTEXPR14 etl::chrono::seconds
operator""_s(
unsigned long long s) ETL_NOEXCEPT
758 return etl::chrono::seconds(
static_cast<etl::chrono::seconds::rep
>(s));
764 #if ETL_USING_VERBOSE_CHRONO_LITERALS
776 #if ETL_USING_VERBOSE_CHRONO_LITERALS
777 inline ETL_CONSTEXPR14 etl::chrono::milliseconds
operator""_milliseconds(
unsigned long long s) ETL_NOEXCEPT
779 inline ETL_CONSTEXPR14 etl::chrono::milliseconds
operator""_ms(
unsigned long long s) ETL_NOEXCEPT
782 return etl::chrono::milliseconds(
static_cast<etl::chrono::milliseconds::rep
>(s));
788 #if ETL_USING_VERBOSE_CHRONO_LITERALS
797 #if (INT_MAX >= INT32_MAX)
801 #if ETL_USING_VERBOSE_CHRONO_LITERALS
802 inline ETL_CONSTEXPR14 etl::chrono::microseconds
operator""_microseconds(
unsigned long long s) ETL_NOEXCEPT
804 inline ETL_CONSTEXPR14 etl::chrono::microseconds
operator""_us(
unsigned long long s) ETL_NOEXCEPT
807 return etl::chrono::microseconds(
static_cast<etl::chrono::microseconds::rep
>(s));
813 #if ETL_USING_VERBOSE_CHRONO_LITERALS
825 #if ETL_USING_VERBOSE_CHRONO_LITERALS
837 #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:293
etl::chrono::duration< int64_t, etl::nano > nanoseconds
Duration types.
Definition duration.h:319
ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration< TRep, TPeriod > &d) ETL_NOEXCEPT
duration_cast
Definition duration.h:343
ETL_CONSTEXPR etl::enable_if< etl::is_integral< T >::value, bool >::type is_even(T value)
Definition binary.h:2188
bitset_ext
Definition absolute.h:40
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1081
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:647
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator-(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:675
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1133
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:570
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:600
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:688
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1147
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:630
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1093
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:665
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:541
ETL_CONSTEXPR14 etl::circular_iterator< TIterator > operator+(etl::circular_iterator< TIterator > &lhs, typename etl::iterator_traits< TIterator >::difference_type offset)
Definition circular_iterator.h:662
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1106
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1120
duration_values
Definition duration.h:74
ratio
Definition ratio.h:53