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// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_CHRONO_FLOOR_HPP
5#define TETL_CHRONO_FLOOR_HPP
6
7#include <etl/_chrono/duration_cast.hpp>
8#include <etl/_chrono/time_point_cast.hpp>
9#include <etl/_type_traits/is_arithmetic.hpp>
10
11namespace etl::chrono {
12
13/// \brief Returns the greatest duration t representable in ToDuration that is
14/// less or equal to d. The function does not participate in the overload
15/// resolution unless ToDuration is an instance of etl::chrono::duration.
16/// \ingroup chrono
17template <typename To, typename Rep, typename Period>
18 requires(detail::is_duration_v<To>)
19[[nodiscard]] constexpr auto
20floor(duration<Rep, Period> const& d) noexcept(is_arithmetic_v<Rep> and is_arithmetic_v<typename To::rep>) -> To
21{
22 auto const t{duration_cast<To>(d)};
23 if (t > d) {
24 return To(t.count() - static_cast<typename To::rep>(1));
25 }
26 return t;
27}
28
29/// \ingroup chrono
30template <typename To, typename Clock, typename Duration>
31 requires(detail::is_duration_v<To>)
32[[nodiscard]] constexpr auto floor(time_point<Clock, Duration> const& tp) -> time_point<Clock, To>
33{
34 return time_point<Clock, To>(floor<To>(tp.time_since_epoch()));
35}
36
37} // namespace etl::chrono
38
39#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:20
constexpr auto floor(time_point< Clock, Duration > const &tp) -> time_point< Clock, To >
Definition floor.hpp:32
Definition abs.hpp:12
Definition adjacent_find.hpp:9
Class template etl::chrono::duration represents a time interval.
Definition duration.hpp:32
Class template time_point represents a point in time. It is implemented as if it stores a value of ty...
Definition time_point.hpp:22