5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_TIME_POINT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_TIME_POINT_HPP_
14#include "arene/base/constraints.hpp"
15#include "arene/base/type_traits/is_instantiation_of.hpp"
16#include "stdlib/include/stdlib_detail/common_type.hpp"
17#include "stdlib/include/stdlib_detail/duration.hpp"
18#include "stdlib/include/stdlib_detail/is_constructible.hpp"
19#include "stdlib/include/stdlib_detail/is_copy_assignable.hpp"
20#include "stdlib/include/stdlib_detail/is_copy_constructible.hpp"
21#include "stdlib/include/stdlib_detail/is_move_assignable.hpp"
22#include "stdlib/include/stdlib_detail/is_move_constructible.hpp"
34template <
class Clock,
class Duration =
typename Clock::duration>
40 "The Duration of a std::time_point must be an instance of std::chrono::duration"
49 using duration = Duration;
51 using rep =
typename duration::rep;
53 using period =
typename duration::period;
57 duration time_since_epoch_;
62 : time_since_epoch_{duration::zero()} {}
67 : time_since_epoch_{epoch_time} {}
72 template <
class Duration2, arene::base::constraints<enable_if_t<is_convertible_v<Duration2, duration>>> =
nullptr>
76 : time_since_epoch_{other.time_since_epoch()} {}
81 return time_since_epoch_;
88 time_since_epoch_ += dur;
96 time_since_epoch_ -= dur;
127template <
class Clock,
class Duration1,
class Rep2,
class Period2>
128constexpr auto operator+(
time_point<Clock, Duration1>
const& left, duration<Rep2, Period2>
const& right)
noexcept(
131 using return_type = time_point<Clock, common_type_t<Duration1, duration<Rep2, Period2>>>;
132 return return_type(left.time_since_epoch() + right);
144template <
class Rep1,
class Period1,
class Clock,
class Duration2>
145constexpr auto operator+(duration<Rep1, Period1>
const& left,
time_point<Clock, Duration2>
const& right)
noexcept(
160template <
class Clock,
class Duration1,
class Rep2,
class Period2>
161constexpr auto operator-(
time_point<Clock, Duration1>
const& left, duration<Rep2, Period2>
const& right)
noexcept(
164 return left + (-right);
175template <
class Clock,
class Duration1,
class Duration2>
179 return left.time_since_epoch() - right.time_since_epoch();
191template <
class Clock,
class Duration1,
class Duration2>
195 return left.time_since_epoch() == right.time_since_epoch();
205template <
class Clock,
class Duration1,
class Duration2>
209 return !(left == right);
219template <
class Clock,
class Duration1,
class Duration2>
223 return left.time_since_epoch() < right.time_since_epoch();
233template <
class Clock,
class Duration1,
class Duration2>
237 return !(right < left);
247template <
class Clock,
class Duration1,
class Duration2>
261template <
class Clock,
class Duration1,
class Duration2>
265 return !(left < right);
A class representing a single point in time for the given clock.
Definition time_point.hpp:35
static constexpr auto min() noexcept(noexcept(time_point{duration::min()})) -> time_point
Get the minimum time_point representable by this class.
Definition time_point.hpp:102
constexpr time_point() noexcept(noexcept(duration(duration::zero())))
Default-construct a time_point referring to clock's epoch.
Definition time_point.hpp:61
auto operator+=(duration const &dur) noexcept(noexcept(time_since_epoch_+=dur)) -> time_point &
Move this time_point forward by a certain duration.
Definition time_point.hpp:87
constexpr auto time_since_epoch() const noexcept(is_nothrow_copy_constructible_v< duration >) -> duration
Return the time of a particular time_point as the duration since its clock's epoch.
Definition time_point.hpp:80
auto operator-=(duration const &dur) noexcept(noexcept(time_since_epoch_ -=dur)) -> time_point &
Move this time_point backward by a certain duration.
Definition time_point.hpp:95
constexpr time_point(time_point< clock, Duration2 > const &other) noexcept(is_nothrow_constructible_v< duration, Duration2 >)
Implicitly convert a time_point for the same clock, potentially even if it has a different duration.
Definition time_point.hpp:74
constexpr time_point(duration const &epoch_time) noexcept(is_nothrow_copy_constructible_v< duration >)
Construct a time_point referring to the point a certain length of time after clock's epoch.
Definition time_point.hpp:66
static constexpr auto max() noexcept(noexcept(time_point{duration::max()})) -> time_point
Get the maximum time_point representable by this class.
Definition time_point.hpp:107
Definition duration.hpp:37
constexpr auto operator==(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(left.time_since_epoch()==right.time_since_epoch())) -> bool
Compare two time points for equality if they're both from the same clock.
Definition time_point.hpp:192
constexpr auto operator+(duration< Rep1, Period1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(right+left)) -> time_point< Clock, common_type_t< duration< Rep1, Period1 >, Duration2 > >
Add a time_point to a duration when the two are compatible.
Definition time_point.hpp:145
constexpr auto operator>(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(right< left)) -> bool
Compare two time points for ordering if they're both from the same clock.
Definition time_point.hpp:248
constexpr auto operator<=(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(right< left)) -> bool
Compare two time points for ordering if they're both from the same clock.
Definition time_point.hpp:234
constexpr auto operator-(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(common_type_t< Duration1, Duration2 >(left.time_since_epoch() - right.time_since_epoch()))) -> common_type_t< Duration1, Duration2 >
Get the duration between two time_points when the two are compatible.
Definition time_point.hpp:176
constexpr auto operator>=(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(left< right)) -> bool
Compare two time points for ordering if they're both from the same clock.
Definition time_point.hpp:262
constexpr auto operator<(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(left.time_since_epoch()< right.time_since_epoch())) -> bool
Compare two time points for ordering if they're both from the same clock.
Definition time_point.hpp:220
constexpr auto operator-(time_point< Clock, Duration1 > const &left, duration< Rep2, Period2 > const &right) noexcept(noexcept(left+(-right))) -> time_point< Clock, common_type_t< Duration1, duration< Rep2, Period2 > > >
Subtract a duration from a time_point when the two are compatible.
Definition time_point.hpp:161
constexpr auto operator+(time_point< Clock, Duration1 > const &left, duration< Rep2, Period2 > const &right) noexcept(noexcept(time_point< Clock, common_type_t< Duration1, duration< Rep2, Period2 > > >(left.time_since_epoch()+right))) -> time_point< Clock, common_type_t< Duration1, duration< Rep2, Period2 > > >
Add a time_point to a duration when the two are compatible.
Definition time_point.hpp:128
constexpr auto operator!=(time_point< Clock, Duration1 > const &left, time_point< Clock, Duration2 > const &right) noexcept(noexcept(left==right)) -> bool
Compare two time points for inequality if they're both from the same clock.
Definition time_point.hpp:206
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827