You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
401B

  1. #if!defined ALGORITHM_HPP
  2. #define ALGORITHM_HPP
  3. #include <functional>
  4. template<class T, class Compare>
  5. constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp )
  6. {
  7. return assert( !comp(hi, lo) ), comp(v, lo) ? lo : comp(hi, v) ? hi : v;
  8. }
  9. template<class T>
  10. constexpr const T& clamp( const T& v, const T& lo, const T& hi )
  11. {
  12. return clamp( v, lo, hi, std::less<T>() );
  13. }
  14. #endif