mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-28 15:34:33 +00:00
Add clamp function to <algorithm>
This commit is contained in:
parent
f009f181b0
commit
740f100843
@ -52,6 +52,19 @@ namespace std
|
|||||||
return (a > b) ? a : b;
|
return (a > b) ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr const T &clamp(const T &v, const T &lo, const T &hi)
|
||||||
|
{
|
||||||
|
return std::max(lo, std::min(v, hi));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T, class Compare>
|
||||||
|
constexpr const T &clamp(const T &v, const T &lo, const T &hi, Compare comp)
|
||||||
|
{
|
||||||
|
return comp(v, lo) ? lo : comp(hi, v) ? hi
|
||||||
|
: v;
|
||||||
|
}
|
||||||
|
|
||||||
template <class InputIt, class T>
|
template <class InputIt, class T>
|
||||||
constexpr InputIt find(InputIt first, InputIt last, const T &value)
|
constexpr InputIt find(InputIt first, InputIt last, const T &value)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user