static_min_max.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Boost integer/static_min_max.hpp header file ----------------------------//
  2. // (C) Copyright Daryle Walker 2001.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // https://www.boost.org/LICENSE_1_0.txt)
  6. // See https://www.boost.org for updates, documentation, and revision history.
  7. #ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP
  8. #define BOOST_INTEGER_STATIC_MIN_MAX_HPP
  9. #include <boost/config.hpp>
  10. #include <boost/integer_fwd.hpp> // self include
  11. namespace boost
  12. {
  13. // Compile-time extrema class declarations ---------------------------------//
  14. // Get the minimum or maximum of two values, signed or unsigned.
  15. template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
  16. struct static_signed_min
  17. {
  18. BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 > Value2) ? Value2 : Value1 );
  19. };
  20. template <static_min_max_signed_type Value1, static_min_max_signed_type Value2>
  21. struct static_signed_max
  22. {
  23. BOOST_STATIC_CONSTANT(static_min_max_signed_type, value = (Value1 < Value2) ? Value2 : Value1 );
  24. };
  25. template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
  26. struct static_unsigned_min
  27. {
  28. BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value
  29. = (Value1 > Value2) ? Value2 : Value1 );
  30. };
  31. template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
  32. struct static_unsigned_max
  33. {
  34. BOOST_STATIC_CONSTANT(static_min_max_unsigned_type, value
  35. = (Value1 < Value2) ? Value2 : Value1 );
  36. };
  37. } // namespace boost
  38. #endif // BOOST_INTEGER_STATIC_MIN_MAX_HPP