tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
duration.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_CHRONO_DURATION_HPP
5#define TETL_CHRONO_DURATION_HPP
6
7#include <etl/_chrono/duration_values.hpp>
8#include <etl/_chrono/treat_as_floating_point.hpp>
9#include <etl/_cstdint/int_least_t.hpp>
10#include <etl/_numeric/gcd.hpp>
11#include <etl/_numeric/lcm.hpp>
12#include <etl/_ratio/ratio.hpp>
13#include <etl/_ratio/ratio_divide.hpp>
14#include <etl/_type_traits/common_type.hpp>
15#include <etl/_type_traits/is_convertible.hpp>
16
17namespace etl::chrono {
18
19/// \ingroup chrono
20/// @{
21
22/// \brief Class template etl::chrono::duration represents a time interval.
23///
24/// \details It consists of a count of ticks of type Rep and a tick period,
25/// where the tick period is a compile-time rational constant representing the
26/// number of seconds from one tick to the next. The only data stored in a
27/// duration is a tick count of type Rep. If Rep is floating point, then the
28/// duration can represent fractions of ticks. Period is included as part of the
29/// duration's type, and is only used when converting between different
30/// durations.
31template <typename Rep, typename Period = etl::ratio<1>>
32struct duration {
33 /// Rep, an arithmetic type representing the number of ticks.
34 using rep = Rep;
35
36 /// A etl::ratio representing the tick period (i.e. the number of
37 /// seconds per tick).
38 using period = typename Period::type;
39
40 /// Constructs a new duration from one of several optional data
41 /// sources. The default constructor is defaulted.
42 constexpr duration() noexcept = default;
43
44 /// Constructs a new duration from one of several optional data
45 /// sources. The copy constructor is defaulted (makes a bitwise copy of the
46 /// tick count).
47 constexpr duration(duration const&) noexcept = default;
48
49 /// Constructs a duration with r ticks.
50 ///
51 /// \details Note that this constructor only participates in overload
52 /// resolution if const Rep2& (the argument type) is implicitly convertible
53 /// to rep (the type of this duration's ticks) and
54 /// treat_as_floating_point<rep>::value is true, or
55 /// treat_as_floating_point<Rep2>::value is false.
56 ///
57 /// That is, a duration with an integer tick count cannot be constructed
58 /// from a floating-point value, but a duration with a floating-point tick
59 /// count can be constructed from an integer value
60 template <typename Rep2>
61 requires(is_convertible_v<Rep2, rep> and (treat_as_floating_point_v<rep> or !treat_as_floating_point_v<Rep2>))
62 constexpr explicit duration(Rep2 const& r) noexcept
63 : _rep(r)
64 {
65 }
66
67 /// Constructs a duration by converting d to an appropriate period
68 /// and tick count, as if by duration_cast<duration>(d).count().
69 ///
70 /// \details In order to prevent truncation during conversion, this
71 /// constructor only participates in overload resolution if computation of
72 /// the conversion factor (by etl::ratio_divide<Period2, Period>) does not
73 /// overflow and:
74 ///
75 /// treat_as_floating_point<rep>::value == true
76 ///
77 /// or both:
78 ///
79 /// ratio_divide<Period2, period>::den == 1, and
80 /// treat_as_floating_point<Rep2>::value == false
81 ///
82 /// That is, either the duration uses floating-point ticks, or Period2 is
83 /// exactly divisible by period
84 template <typename Rep2, typename Period2>
85 requires(
86 treat_as_floating_point_v<rep>
87 or (ratio_divide<Period2, period>::den == 1 and not treat_as_floating_point_v<Rep2>)
88 )
89 constexpr duration(duration<Rep2, Period2> const& other) noexcept
90 : _rep(static_cast<Rep>(other.count() * ratio_divide<Period2, period>::num))
91 {
92 }
93
94 /// Assigns the contents of one duration to another.
95 auto operator=(duration const& other) -> duration& = default;
96
97 /// Returns the number of ticks for this duration.
98 [[nodiscard]] constexpr auto count() const -> rep
99 {
100 return _rep;
101 }
102
103 /// Returns a zero-length duration.
104 [[nodiscard]] static constexpr auto zero() noexcept -> duration
105 {
106 return duration(etl::chrono::duration_values<rep>::zero());
107 }
108
109 /// Returns a duration with the lowest possible value.
110 [[nodiscard]] static constexpr auto min() noexcept -> duration
111 {
112 return duration(etl::chrono::duration_values<rep>::min());
113 }
114
115 /// Returns a duration with the largest possible value.
116 [[nodiscard]] static constexpr auto max() noexcept -> duration
117 {
118 return duration(etl::chrono::duration_values<rep>::max());
119 }
120
121 /// Implements unary plus and unary minus for the durations.
122 [[nodiscard]] constexpr auto operator+() const -> etl::common_type_t<duration>
123 {
124 return etl::common_type_t<duration>(*this);
125 }
126
127 /// Implements unary plus and unary minus for the durations.
128 [[nodiscard]] constexpr auto operator-() const -> etl::common_type_t<duration>
129 {
130 return etl::common_type_t<duration>(-_rep);
131 }
132
133 /// Increments or decrements the number of ticks for this duration.
134 /// Equivalent to ++_rep; return *this;
135 constexpr auto operator++() -> duration&
136 {
137 ++_rep;
138 return *this;
139 }
140
141 /// Increments or decrements the number of ticks for this duration.
142 /// Equivalent to return duration(_rep++)
143 constexpr auto operator++(int) -> duration
144 {
145 return duration(_rep++);
146 }
147
148 /// Increments or decrements the number of ticks for this duration.
149 /// Equivalent to --_rep; return *this;
150 constexpr auto operator--() -> duration&
151 {
152 --_rep;
153 return *this;
154 }
155
156 /// Increments or decrements the number of ticks for this duration.
157 /// Equivalent to return duration(_rep--);
158 constexpr auto operator--(int) -> duration
159 {
160 return duration(_rep--);
161 }
162
163 /// Performs compound assignments between two durations with the same
164 /// period or between a duration and a tick count value.
165 constexpr auto operator+=(duration const& d) noexcept -> duration&
166 {
167 _rep += d.count();
168 return *this;
169 }
170
171 /// Performs compound assignments between two durations with the same
172 /// period or between a duration and a tick count value.
173 constexpr auto operator-=(duration const& d) noexcept -> duration&
174 {
175 _rep -= d.count();
176 return *this;
177 }
178
179 /// Performs compound assignments between two durations with the same
180 /// period or between a duration and a tick count value.
181 constexpr auto operator*=(rep const& rhs) noexcept -> duration&
182 {
183 _rep *= rhs;
184 return *this;
185 }
186
187 /// Performs compound assignments between two durations with the same
188 /// period or between a duration and a tick count value.
189 constexpr auto operator/=(rep const& rhs) noexcept -> duration&
190 {
191 _rep /= rhs;
192 return *this;
193 }
194
195 /// Performs compound assignments between two durations with the same
196 /// period or between a duration and a tick count value.
197 constexpr auto operator%=(rep const& rhs) noexcept -> duration&
198 {
199 _rep %= rhs;
200 return *this;
201 }
202
203 /// Performs compound assignments between two durations with the same
204 /// period or between a duration and a tick count value.
205 constexpr auto operator%=(duration const& rhs) noexcept -> duration&
206 {
207 _rep %= rhs.count();
208 return *this;
209 }
210
211private:
212 rep _rep{};
213};
214
215} // namespace etl::chrono
216
217namespace etl {
218
219/// Exposes the type named type, which is the common type of two
220/// etl::chrono::durations, whose period is the greatest common divisor of
221/// Period1 and Period2.
222///
223/// The period of the resulting duration can be computed by forming a
224/// ratio of the greatest common divisor of Period1::num and Period2::num and
225/// the least common multiple of Period1::den and Period2::den.
226template <typename Rep1, typename Period1, typename Rep2, typename Period2>
227struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>> {
228private:
229 static constexpr auto num = gcd(Period1::num, Period2::num);
230 static constexpr auto den = lcm(Period1::den, Period2::den);
231
232public:
233 using type = chrono::duration<common_type_t<Rep1, Rep2>, ratio<num, den>>;
234};
235
236} // namespace etl
237
238namespace etl::chrono {
239
240/// Performs basic arithmetic operations between two durations or between
241/// a duration and a tick count.
242///
243/// \details Converts the two durations to their common type and creates a
244/// duration whose tick count is the sum of the tick counts after conversion.
245///
246/// https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
247template <typename Rep1, typename Period1, typename Rep2, typename Period2>
248[[nodiscard]] constexpr auto operator+(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs)
249 -> common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
250{
251 using CD = common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>;
252 using CR = typename CD::rep;
253 return CD(static_cast<CR>(CD(lhs).count() + CD(rhs).count()));
254}
255
256/// Performs basic arithmetic operations between two durations or between
257/// a duration and a tick count.
258///
259/// \details Converts the two durations to their common type and creates a
260/// duration whose tick count is the rhs number of ticks subtracted from the lhs
261/// number of ticks after conversion.
262///
263/// https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
264template <typename Rep1, typename Period1, typename Rep2, typename Period2>
265[[nodiscard]] constexpr auto operator-(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs)
266 -> common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
267{
268 using CD = common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>;
269 using CR = typename CD::rep;
270 return CD(static_cast<CR>(CD(lhs).count() - CD(rhs).count()));
271}
272
273/// Performs basic arithmetic operations between two durations or between
274/// a duration and a tick count.
275///
276/// \details Converts the two durations to their common type and creates a
277/// duration whose tick count is the rhs number of ticks subtracted from the lhs
278/// number of ticks after conversion.
279///
280/// https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
281template <typename Rep1, typename Period1, typename Rep2, typename Period2>
282[[nodiscard]] constexpr auto operator/(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs)
283 -> common_type_t<Rep1, Rep2>
284{
285 using CD = common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>;
286 return CD(lhs).count() / CD(rhs).count();
287}
288
289/// Performs basic arithmetic operations between two durations or between
290/// a duration and a tick count.
291///
292/// \details Converts the two durations to their common type and creates a
293/// duration whose tick count is the remainder of the tick counts after
294/// conversion.
295///
296/// https://en.cppreference.com/w/cpp/chrono/duration/operator_arith4
297template <typename Rep1, typename Period1, typename Rep2, typename Period2>
298[[nodiscard]] constexpr auto operator%(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs)
299 -> common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>
300{
301 using CD = common_type_t<duration<Rep1, Period1>, duration<Rep2, Period2>>;
302 using CR = typename CD::rep;
303 return CD(static_cast<CR>(CD(lhs).count() % CD(rhs).count()));
304}
305
306/// Compares two durations. Checks if lhs and rhs are equal, i.e. the
307/// number of ticks for the type common to both durations are equal.
308template <typename Rep1, typename Period1, typename Rep2, typename Period2>
309[[nodiscard]] constexpr auto operator==(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
310{
311 using common_t = typename etl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type;
312 return common_t(lhs).count() == common_t(rhs).count();
313}
314
315/// Compares two durations. Checks if lhs and rhs are equal, i.e. the
316/// number of ticks for the type common to both durations are equal.
317template <typename Rep1, typename Period1, typename Rep2, typename Period2>
318[[nodiscard]] constexpr auto operator!=(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
319{
320 return !(lhs == rhs);
321}
322
323/// Compares two durations. Compares lhs to rhs, i.e. compares the number
324/// of ticks for the type common to both durations.
325template <typename Rep1, typename Period1, typename Rep2, typename Period2>
326[[nodiscard]] constexpr auto operator<(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
327{
328 using common_t = typename etl::common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type;
329 return common_t(lhs).count() < common_t(rhs).count();
330}
331
332/// Compares two durations. Compares lhs to rhs, i.e. compares the number
333/// of ticks for the type common to both durations.
334template <typename Rep1, typename Period1, typename Rep2, typename Period2>
335[[nodiscard]] constexpr auto operator<=(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
336{
337 return !(rhs < lhs);
338}
339
340/// Compares two durations. Compares lhs to rhs, i.e. compares the number
341/// of ticks for the type common to both durations.
342template <typename Rep1, typename Period1, typename Rep2, typename Period2>
343[[nodiscard]] constexpr auto operator>(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
344{
345 return rhs < lhs;
346}
347
348/// Compares two durations. Compares lhs to rhs, i.e. compares the number
349/// of ticks for the type common to both durations.
350template <typename Rep1, typename Period1, typename Rep2, typename Period2>
351[[nodiscard]] constexpr auto operator>=(duration<Rep1, Period1> const& lhs, duration<Rep2, Period2> const& rhs) -> bool
352{
353 return !(lhs < rhs);
354}
355
356/// Signed integer type of at least 64 bits.
357using nanoseconds = duration<int_least64_t, nano>;
358
359/// Signed integer type of at least 55 bits.
360using microseconds = duration<int_least64_t, micro>;
361
362/// Signed integer type of at least 45 bits.
363using milliseconds = duration<int_least64_t, milli>;
364
365/// Signed integer type of at least 35 bits.
366using seconds = duration<int_least64_t>;
367
368/// Signed integer type of at least 29 bits.
369using minutes = duration<int_least32_t, ratio<60>>;
370
371/// Signed integer type of at least 23 bits.
372using hours = duration<int_least32_t, ratio<3600>>;
373
374/// Signed integer type of at least 25 bits.
375using days = duration<int_least32_t, ratio<86400>>;
376
377/// Signed integer type of at least 22 bits.
378using weeks = duration<int_least32_t, ratio<604800>>;
379
380/// Signed integer type of at least 20 bits.
381using months = duration<int_least32_t, ratio<31556952>>;
382
383/// Signed integer type of at least 17 bits.
384using years = duration<int_least32_t, ratio<2629746>>;
385
386/// @}
387
388} // namespace etl::chrono
389
390// NOLINTNEXTLINE(modernize-concat-nested-namespaces)
391namespace etl {
392
393inline namespace literals {
394inline namespace chrono_literals {
395
396/// Forms a etl::chrono::duration literal representing hours.
397/// Integer literal, returns exactly etl::chrono::hours(hrs).
398constexpr auto operator""_h(unsigned long long h) -> etl::chrono::hours
399{
400 return etl::chrono::hours(static_cast<etl::chrono::hours::rep>(h));
401}
402
403/// Forms a etl::chrono::duration literal representing hours.
404/// Floating-point literal, returns a floating-point duration equivalent
405/// to etl::chrono::hours.
406constexpr auto operator""_h(long double h) -> etl::chrono::duration<long double, ratio<3600, 1>>
407{
408 return etl::chrono::duration<long double, etl::ratio<3600, 1>>(h);
409}
410
411/// Forms a etl::chrono::duration literal representing minutes.
412/// Integer literal, returns exactly etl::chrono::minutes(mins).
413constexpr auto operator""_min(unsigned long long m) -> etl::chrono::minutes
414{
415 return etl::chrono::minutes(static_cast<etl::chrono::minutes::rep>(m));
416}
417
418/// Forms a etl::chrono::duration literal representing minutes.
419/// Floating-point literal, returns a floating-point duration equivalent
420/// to etl::chrono::minutes.
421constexpr auto operator""_min(long double m) -> etl::chrono::duration<long double, etl::ratio<60, 1>>
422{
423 return etl::chrono::duration<long double, ratio<60, 1>>(m);
424}
425
426/// Forms a etl::chrono::duration literal representing seconds.
427/// Integer literal, returns exactly etl::chrono::seconds(mins).
428constexpr auto operator""_s(unsigned long long m) -> etl::chrono::seconds
429{
430 return etl::chrono::seconds(static_cast<etl::chrono::seconds::rep>(m));
431}
432
433/// Forms a etl::chrono::duration literal representing seconds.
434/// Floating-point literal, returns a floating-point duration equivalent
435/// to etl::chrono::seconds.
436constexpr auto operator""_s(long double m) -> etl::chrono::duration<long double>
437{
438 return etl::chrono::duration<long double>(m);
439}
440
441/// Forms a etl::chrono::duration literal representing
442/// milliseconds. Integer literal, returns exactly
443/// etl::chrono::milliseconds(mins).
444constexpr auto operator""_ms(unsigned long long m) -> etl::chrono::milliseconds
445{
446 return etl::chrono::milliseconds(static_cast<etl::chrono::milliseconds::rep>(m));
447}
448
449/// Forms a etl::chrono::duration literal representing
450/// milliseconds. Floating-point literal, returns a floating-point
451/// duration equivalent to etl::chrono::milliseconds.
452constexpr auto operator""_ms(long double m) -> etl::chrono::duration<long double, etl::milli>
453{
454 return etl::chrono::duration<long double, etl::milli>(m);
455}
456
457/// Forms a etl::chrono::duration literal representing
458/// microseconds. Integer literal, returns exactly
459/// etl::chrono::microseconds(mins).
460constexpr auto operator""_us(unsigned long long m) -> etl::chrono::microseconds
461{
462 return etl::chrono::microseconds(static_cast<etl::chrono::microseconds::rep>(m));
463}
464
465/// Forms a etl::chrono::duration literal representing
466/// microseconds. Floating-point literal, returns a floating-point
467/// duration equivalent to etl::chrono::microseconds.
468constexpr auto operator""_us(long double m) -> etl::chrono::duration<long double, etl::micro>
469{
470 return etl::chrono::duration<long double, etl::micro>(m);
471}
472
473/// Forms a etl::chrono::duration literal representing
474/// nanoseconds. Integer literal, returns exactly
475/// etl::chrono::nanoseconds(mins).
476constexpr auto operator""_ns(unsigned long long m) -> etl::chrono::nanoseconds
477{
478 return etl::chrono::nanoseconds(static_cast<etl::chrono::nanoseconds::rep>(m));
479}
480
481/// Forms a etl::chrono::duration literal representing
482/// nanoseconds. Floating-point literal, returns a floating-point
483/// duration equivalent to etl::chrono::nanoseconds.
484constexpr auto operator""_ns(long double m) -> etl::chrono::duration<long double, etl::nano>
485{
486 return etl::chrono::duration<long double, etl::nano>(m);
487}
488
489} // namespace chrono_literals
490} // namespace literals
491} // namespace etl
492
493namespace etl::chrono {
494using namespace etl::literals::chrono_literals;
495} // namespace etl::chrono
496
497#endif // TETL_CHRONO_DURATION_HPP
Definition abs.hpp:12
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:298
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:326
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:343
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:309
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:318
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:248
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:282
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:335
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:265
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:351
Definition day.hpp:130
constexpr auto operator""_ms(unsigned long long m) -> etl::chrono::milliseconds
Forms a etl::chrono::duration literal representing milliseconds. Integer literal, returns exactly etl...
Definition duration.hpp:444
constexpr auto operator""_min(unsigned long long m) -> etl::chrono::minutes
Forms a etl::chrono::duration literal representing minutes. Integer literal, returns exactly etl::chr...
Definition duration.hpp:413
constexpr auto operator""_us(long double m) -> etl::chrono::duration< long double, etl::micro >
Forms a etl::chrono::duration literal representing microseconds. Floating-point literal,...
Definition duration.hpp:468
constexpr auto operator""_s(long double m) -> etl::chrono::duration< long double >
Forms a etl::chrono::duration literal representing seconds. Floating-point literal,...
Definition duration.hpp:436
constexpr auto operator""_ns(unsigned long long m) -> etl::chrono::nanoseconds
Forms a etl::chrono::duration literal representing nanoseconds. Integer literal, returns exactly etl:...
Definition duration.hpp:476
constexpr auto operator""_ns(long double m) -> etl::chrono::duration< long double, etl::nano >
Forms a etl::chrono::duration literal representing nanoseconds. Floating-point literal,...
Definition duration.hpp:484
constexpr auto operator""_us(unsigned long long m) -> etl::chrono::microseconds
Forms a etl::chrono::duration literal representing microseconds. Integer literal, returns exactly etl...
Definition duration.hpp:460
constexpr auto operator""_ms(long double m) -> etl::chrono::duration< long double, etl::milli >
Forms a etl::chrono::duration literal representing milliseconds. Floating-point literal,...
Definition duration.hpp:452
constexpr auto operator""_h(unsigned long long h) -> etl::chrono::hours
Forms a etl::chrono::duration literal representing hours. Integer literal, returns exactly etl::chron...
Definition duration.hpp:398
constexpr auto operator""_s(unsigned long long m) -> etl::chrono::seconds
Forms a etl::chrono::duration literal representing seconds. Integer literal, returns exactly etl::chr...
Definition duration.hpp:428
constexpr auto operator""_h(long double h) -> etl::chrono::duration< long double, ratio< 3600, 1 > >
Forms a etl::chrono::duration literal representing hours. Floating-point literal, returns a floating-...
Definition duration.hpp:406
constexpr auto operator""_min(long double m) -> etl::chrono::duration< long double, etl::ratio< 60, 1 > >
Forms a etl::chrono::duration literal representing minutes. Floating-point literal,...
Definition duration.hpp:421
Definition day.hpp:129
Definition adjacent_find.hpp:9
The etl::chrono::duration_values type defines three common durations.
Definition duration_values.hpp:20
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:32
static constexpr auto min() noexcept -> duration
Returns a duration with the lowest possible value.
Definition duration.hpp:110
constexpr auto count() const -> rep
Returns the number of ticks for this duration.
Definition duration.hpp:98
constexpr auto operator--() -> duration &
Increments or decrements the number of ticks for this duration. Equivalent to –_rep; return *this;.
Definition duration.hpp:150
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:189
constexpr duration(duration const &) noexcept=default
Constructs a new duration from one of several optional data sources. The copy constructor is defaulte...
constexpr duration(Rep2 const &r) noexcept
Constructs a duration with r ticks.
Definition duration.hpp:62
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:173
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:165
constexpr auto operator+() const -> etl::common_type_t< duration >
Implements unary plus and unary minus for the durations.
Definition duration.hpp:122
constexpr auto operator++(int) -> duration
Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep++)
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:197
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:104
constexpr auto operator-() const -> etl::common_type_t< duration >
Implements unary plus and unary minus for the durations.
Definition duration.hpp:128
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:181
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:89
static constexpr auto max() noexcept -> duration
Returns a duration with the largest possible value.
Definition duration.hpp:116
constexpr auto operator--(int) -> duration
Increments or decrements the number of ticks for this duration. Equivalent to return duration(_rep–);...
Definition duration.hpp:158
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:205
constexpr auto operator++() -> duration &
Increments or decrements the number of ticks for this duration. Equivalent to ++_rep; return *this;.
Definition duration.hpp:135
constexpr duration() noexcept=default
Constructs a new duration from one of several optional data sources. The default constructor is defau...
The typename template provides compile-time rational arithmetic support. Each instantiation of this t...
Definition ratio.hpp:22