tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
in_range.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_UTILITY_IN_RANGE_HPP
5#define TETL_UTILITY_IN_RANGE_HPP
6
7#include <etl/_concepts/builtin_integer.hpp>
8#include <etl/_limits/numeric_limits.hpp>
9#include <etl/_utility/cmp_greater_equal.hpp>
10#include <etl/_utility/cmp_less_equal.hpp>
11
12namespace etl {
13
14/// Returns true if the value of t is in the range of values that can be
15/// represented in R, that is, if t can be converted to R without data loss.
16///
17/// https://en.cppreference.com/w/cpp/utility/in_range
18///
19/// \ingroup utility
20template <builtin_integer R, builtin_integer T>
21[[nodiscard]] constexpr auto in_range(T t) noexcept -> bool
22{
23 using limits = etl::numeric_limits<R>;
24 return etl::cmp_greater_equal(t, limits::min()) and etl::cmp_less_equal(t, limits::max());
25}
26
27} // namespace etl
28
29#endif // TETL_UTILITY_IN_RANGE_HPP
constexpr auto in_range(T t) noexcept -> bool
Returns true if the value of t is in the range of values that can be represented in R,...
Definition in_range.hpp:21
Definition adjacent_find.hpp:9
Definition numeric_limits.hpp:18