tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
ceil.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_CEIL_HPP
5#define TETL_CHRONO_CEIL_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/// \ingroup chrono
14template <typename To, typename Rep, typename Period>
15 requires(detail::is_duration_v<To>)
16[[nodiscard]] constexpr auto
17ceil(duration<Rep, Period> const& d) noexcept(is_arithmetic_v<Rep> and is_arithmetic_v<typename To::rep>) -> To
18{
19 auto const t{duration_cast<To>(d)};
20 if (t < d) {
21 return To{t.count() + static_cast<typename To::rep>(1)};
22 }
23 return t;
24}
25
26/// \ingroup chrono
27template <typename To, typename Clock, typename Duration>
28 requires(detail::is_duration_v<To>)
29[[nodiscard]] constexpr auto ceil(time_point<Clock, Duration> const& tp) -> time_point<Clock, To>
30{
31 return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
32}
33
34} // namespace etl::chrono
35
36#endif // TETL_CHRONO_CEIL_HPP
constexpr auto ceil(time_point< Clock, Duration > const &tp) -> time_point< Clock, To >
Definition ceil.hpp:29
constexpr auto ceil(duration< Rep, Period > const &d) noexcept(is_arithmetic_v< Rep > and is_arithmetic_v< typename To::rep >) -> To
Definition ceil.hpp:17
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