VCCC  2024.05
VisualCamp Common C++ library
clamp.hpp
Go to the documentation of this file.
1 //
2 // Created by YongGyu Lee on 1/26/24.
3 //
4 
5 #ifndef VCCC_ALGORITHM_CLAMP_HPP
6 #define VCCC_ALGORITHM_CLAMP_HPP
7 
8 #include <functional>
9 
10 namespace vccc {
11 
14 
15 template<typename T, typename Compare>
16 constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp) {
17  return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
18 }
19 
20 template<typename T>
21 constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
22  return vccc::clamp(v, lo, hi, std::less<>{});
23 }
24 
26 
27 } // namespace vccc
28 
29 #endif // VCCC_ALGORITHM_CLAMP_HPP
constexpr const T & clamp(const T &v, const T &lo, const T &hi, Compare comp)
Definition: clamp.hpp:16
Definition: directory.h:12