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
6
#include <
etl/_functional/less.hpp
>
7
8
namespace
etl
{
9
12
16
template
<
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
22
template
<
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
etl::clamp
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
less.hpp
etl
Definition
adjacent_find.hpp:8
etl::less
Function object for performing comparisons. Unless specialised, invokes operator< on type T....
Definition
less.hpp:14
include
etl
_algorithm
clamp.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0