mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-04 14:14:09 +00:00
add algorithm clamp, clamp_range_copy, clamp_range
This commit is contained in:
parent
de41f5c880
commit
79ea4f0885
29 changed files with 870 additions and 11 deletions
30
sprout/algorithm/clamp.hpp
Normal file
30
sprout/algorithm/clamp.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#ifndef SPROUT_ALGORITHM_CLAMP_HPP
|
||||
#define SPROUT_ALGORITHM_CLAMP_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// clamp
|
||||
//
|
||||
template<typename T, typename Compare>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
clamp(T const& value, typename std::common_type<T>::type const& low, typename std::common_type<T>::type const& high, Compare comp) {
|
||||
return comp(value, low) ? low
|
||||
: comp(high, value) ? high
|
||||
: value
|
||||
;
|
||||
}
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR T const&
|
||||
clamp(T const& value, typename std::common_type<T>::type const& low, typename std::common_type<T>::type const& high) {
|
||||
return sprout::clamp(
|
||||
value, low, high,
|
||||
NS_SSCRISK_CEL_OR_SPROUT::less<T>()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ALGORITHM_CLAMP_HPP
|
Loading…
Add table
Add a link
Reference in a new issue