add algorithm clamp, clamp_range_copy, clamp_range

This commit is contained in:
bolero-MURAKAMI 2012-10-13 21:06:32 +09:00
parent de41f5c880
commit 79ea4f0885
29 changed files with 870 additions and 11 deletions

View 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