tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
clamp.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_ALGORITHM_CLAMP_HPP
4#define TETL_ALGORITHM_CLAMP_HPP
5
7
8namespace etl {
9
12
16template <typename Type, typename Compare>
17[[nodiscard]] constexpr auto clamp(Type const& v, Type const& lo, Type const& hi, Compare comp) -> Type const&
18{
19 return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
20}
21
22template <typename Type>
23[[nodiscard]] constexpr auto clamp(Type const& v, Type const& lo, Type const& hi) noexcept -> Type const&
24{
25 return etl::clamp(v, lo, hi, etl::less<Type>());
26}
27
29
30} // namespace etl
31
32#endif // TETL_ALGORITHM_CLAMP_HPP
constexpr auto clamp(Type const &v, Type const &lo, Type const &hi, Compare comp) -> Type const &
If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise r...
Definition clamp.hpp:17
Definition adjacent_find.hpp:8
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition less.hpp:14