7 namespace honey {
template<
class Rep,
class Period>
class Duration; }
13 template<
class Rep,
class Period,
class Rep2,
class Period2>
24 template<
class Rep_,
class Period_ = Ratio<1>>
27 template<
class Rep,
class Period>
friend class Duration;
32 static_assert(Period::num > 0,
"Period can't be negative or 0");
37 constexpr
explicit Duration(
const Rep2& rep) : _rep(rep) {}
39 template<class Rep2, class Period2, class Ratio = typename Period2::template div<Period>::type>
42 template<class Rep2, class Period2, class Ratio = typename Period2::template div<Period>::type>
60 template<
class Rep2,
class Period2,
class DurCommon =
typename std::common_type<Duration, Duration<Rep2,Period2>>::type>
63 template<
class Rep2,
class Period2>
66 template<
class Rep2,
class Period2,
class DurCommon =
typename std::common_type<Duration, Duration<Rep2,Period2>>::type>
67 constexpr
bool operator<(const Duration<Rep2,Period2>& rhs)
const {
return DurCommon(*this)._rep < DurCommon(rhs)._rep; }
69 template<
class Rep2,
class Period2>
72 template<
class Rep2,
class Period2>
73 constexpr
bool operator<=(const Duration<Rep2,Period2>& rhs)
const {
return !(rhs < *
this); }
75 template<
class Rep2,
class Period2>
79 constexpr Rep
count()
const {
return _rep; }
97 template<
class Rep,
class Period,
class Rep2,
class Period2,
98 class DurCommon =
typename std::common_type<Duration<Rep,Period>, Duration<Rep2,Period2>>::type>
101 return DurCommon(DurCommon(lhs).count() + DurCommon(rhs).count());
104 template<
class Rep,
class Period,
class Rep2,
class Period2,
108 return DurCommon(DurCommon(lhs).count() - DurCommon(rhs).count());
111 template<
class Rep,
class Period,
class Rep2,
115 return DurCommon(DurCommon(lhs).count() * rhs);
118 template<
class Rep,
class Rep2,
class Period,
125 template<
class Rep,
class Period,
class Rep2,
130 return DurCommon(DurCommon(lhs).count() / rhs);
133 template<
class Rep,
class Period,
class Rep2,
class Period2,
135 class RepCommon =
typename std::common_type<Rep,Rep2>::type>
138 return DurCommon(lhs).count() / DurCommon(rhs).count();
141 template<
class Rep,
class Period,
class Rep2,
142 typename mt::disable_if<mt::isSpecializationOf<Rep2, Duration>::value,
int>::type=0,
146 return DurCommon(DurCommon(lhs).count() % rhs);
149 template<
class Rep,
class Period,
class Rep2,
class Period2,
153 return DurCommon(DurCommon(lhs).count() % DurCommon(rhs).count());
174 constexpr Nanosec
operator"" _ns(
unsigned long long int n) {
return Nanosec(static_cast<Nanosec::Rep>(n)); }
176 constexpr Microsec
operator"" _us(
unsigned long long int n) {
return Microsec(static_cast<Microsec::Rep>(n)); }
178 constexpr Millisec
operator"" _ms(
unsigned long long int n) {
return Millisec(static_cast<Millisec::Rep>(n)); }
180 constexpr Seconds
operator"" _s(
unsigned long long int n) {
return Seconds(static_cast<Seconds::Rep>(n)); }
182 constexpr Minutes
operator"" _min(
unsigned long long int n) {
return Minutes(static_cast<Minutes::Rep>(n)); }
184 constexpr Hours
operator"" _h(
unsigned long long int n) {
return Hours(static_cast<Hours::Rep>(n)); }
193 template<
class Rep,
class Period>
194 ostream& operator<<(ostream& os, const honey::Duration<Rep,Period>& d) {
return os << d.count(); }
constexpr bool operator==(const Duration< Rep2, Period2 > &rhs) const
Definition: Duration.h:61
constexpr Duration()=default
Duration< int64, ratio::Unit > Seconds
Definition: Duration.h:163
Rep_ Rep
Definition: Duration.h:29
Period_ Period
Definition: Duration.h:30
constexpr Duration operator-() const
Definition: Duration.h:50
Class to hold compile-time finite rational numbers, ie. the fraction num / den.
Definition: Ratio.h:11
constexpr Duration(const Duration< Rep2, Period2 > &d)
Construct from another type of duration.
Definition: Duration.h:40
Duration & operator*=(const Rep &rhs)
Definition: Duration.h:55
static const int64 num
Definition: Ratio.h:20
Duration & operator++()
Definition: Duration.h:46
Duration< int64, ratio::Micro > Microsec
Definition: Duration.h:161
static const int64 den
Definition: Ratio.h:21
constexpr DurCommon operator/(const Duration< Rep, Period > &lhs, const Rep2 &rhs)
operator/(Duration, Rep). Returns a duration of best-fit period and repetition types.
Definition: Duration.h:128
constexpr bool operator!=(const Duration< Rep2, Period2 > &rhs) const
Definition: Duration.h:64
constexpr Rep count() const
Get number of repetitions of period.
Definition: Duration.h:79
constexpr DurCommon operator*(const Duration< Rep, Period > &lhs, const Rep2 &rhs)
operator*(Duration, Rep). Returns a duration of best-fit period and repetition types.
Definition: Duration.h:113
Duration operator--(int) const
Definition: Duration.h:52
Duration< int64, ratio::Nano > Nanosec
Definition: Duration.h:160
Duration< int, Seconds::Period::mul< Ratio< 60 > >::type > Minutes
Definition: Duration.h:164
constexpr bool operator>=(const Duration< Rep2, Period2 > &rhs) const
Definition: Duration.h:76
Duration< int64, ratio::Milli > Millisec
Definition: Duration.h:162
constexpr bool operator>(const Duration< Rep2, Period2 > &rhs) const
Definition: Duration.h:70
constexpr DurCommon operator%(const Duration< Rep, Period > &lhs, const Duration< Rep2, Period2 > &rhs)
operator%(Duration, Duration). Returns a duration of best-fit period and repetition types...
Definition: Duration.h:151
constexpr DurCommon operator%(const Duration< Rep, Period > &lhs, const Rep2 &rhs)
operator%(Duration, Rep). Returns a duration of best-fit period and repetition types.
Definition: Duration.h:144
Duration & operator--()
Definition: Duration.h:51
constexpr DurCommon operator+(const Duration< Rep, Period > &lhs, const Duration< Rep2, Period2 > &rhs)
operator+(Duration, Duration). Returns a duration with best-fit period and repetition types...
Definition: Duration.h:99
constexpr Duration operator+() const
Definition: Duration.h:45
constexpr DurCommon operator*(const Rep &lhs, const Duration< Rep2, Period > &rhs)
operator*(Rep, Duration). Returns a duration of best-fit period and repetition types.
Definition: Duration.h:120
Duration & operator%=(const Rep &rhs)
Definition: Duration.h:57
static constexpr Duration max()
Maximum duration (positive reps)
Definition: Duration.h:86
Duration & operator%=(const Duration &rhs)
Definition: Duration.h:58
Duration & operator/=(const Rep &rhs)
Definition: Duration.h:56
Duration< int, Minutes::Period::mul< Ratio< 60 > >::type > Hours
Definition: Duration.h:165
honey::Duration< typename common_type< Rep, Rep2 >::type, typename common_type< Period, Period2 >::type > type
Definition: Duration.h:16
Duration represented by repetitions of a period. The period must be a ratio.
Definition: Duration.h:7
constexpr Duration(const Rep2 &rep)
Construct from repetition.
Definition: Duration.h:37
constexpr DurCommon operator-(const Duration< Rep, Period > &lhs, const Duration< Rep2, Period2 > &rhs)
operator-(Duration, Duration). Returns a duration with best-fit period and repetition types...
Definition: Duration.h:106
constexpr RepCommon operator/(const Duration< Rep, Period > &lhs, const Duration< Rep2, Period2 > &rhs)
operator/(Duration, Duration). Returns a repetition of best-fit type.
Definition: Duration.h:136
static constexpr Duration zero()
Zero duration.
Definition: Duration.h:82
Duration & operator+=(const Duration &rhs)
Definition: Duration.h:48
Duration< int, Hours::Period::mul< Ratio< 24 > >::type > Days
Definition: Duration.h:166
Duration operator++(int) const
Definition: Duration.h:47
Duration & operator=(const Duration< Rep2, Period2 > &rhs)
Definition: Duration.h:43
static constexpr Duration min()
Minimum duration (negative reps)
Definition: Duration.h:84
Duration & operator-=(const Duration &rhs)
Definition: Duration.h:53
Global Honeycomb namespace.