tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
floor.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CHRONO_FLOOR_HPP
4#define TETL_CHRONO_FLOOR_HPP
5
9
10namespace etl::chrono {
11
16template <typename To, typename Rep, typename Period>
17 requires(detail::is_duration_v<To>)
18[[nodiscard]] constexpr auto floor(duration<Rep, Period> const& d)
20{
21 auto const t{duration_cast<To>(d)};
22 if (t > d) {
23 return To(t.count() - static_cast<typename To::rep>(1));
24 }
25 return t;
26}
27
29template <typename To, typename Clock, typename Duration>
30 requires(detail::is_duration_v<To>)
31[[nodiscard]] constexpr auto floor(time_point<Clock, Duration> const& tp) -> time_point<Clock, To>
32{
34}
35
36} // namespace etl::chrono
37
38#endif // TETL_CHRONO_FLOOR_HPP
constexpr auto floor(duration< Rep, Period > const &d) noexcept(is_arithmetic_v< Rep > and is_arithmetic_v< typename To::rep >) -> To
Returns the greatest duration t representable in ToDuration that is less or equal to d....
Definition floor.hpp:18
constexpr auto duration_cast(duration< Rep, Period > const &duration) noexcept(is_arithmetic_v< Rep > and is_arithmetic_v< typename ToDur::rep >) -> ToDur
Converts a duration to a duration of different type ToDur.
Definition duration_cast.hpp:77
Definition abs.hpp:11
constexpr bool is_arithmetic_v
Definition is_arithmetic.hpp:21
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:31
Class template time_point represents a point in time. It is implemented as if it stores a value of ty...
Definition time_point.hpp:21
constexpr auto time_since_epoch() const noexcept -> duration
Returns a duration representing the amount of time between *this and the clock's epoch.
Definition time_point.hpp:61