safe_integer_range.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef BOOST_NUMERIC_SAFE_INTEGER_RANGE_HPP
  2. #define BOOST_NUMERIC_SAFE_INTEGER_RANGE_HPP
  3. // Copyright (c) 2012 Robert Ramey
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #include <cstdint> // intmax_t, uintmax_t
  9. #include "utility.hpp"
  10. #include "safe_integer.hpp"
  11. #include "native.hpp"
  12. #include "exception_policies.hpp"
  13. /////////////////////////////////////////////////////////////////
  14. // higher level types implemented in terms of safe_base
  15. namespace boost {
  16. namespace safe_numerics {
  17. /////////////////////////////////////////////////////////////////
  18. // safe_signed_range
  19. template <
  20. std::intmax_t Min,
  21. std::intmax_t Max,
  22. class P = native,
  23. class E = default_exception_policy
  24. >
  25. using safe_signed_range = safe_base<
  26. typename utility::signed_stored_type<Min, Max>,
  27. static_cast<typename utility::signed_stored_type<Min, Max> >(Min),
  28. static_cast<typename utility::signed_stored_type<Min, Max> >(Max),
  29. P,
  30. E
  31. >;
  32. /////////////////////////////////////////////////////////////////
  33. // safe_unsigned_range
  34. template <
  35. std::uintmax_t Min,
  36. std::uintmax_t Max,
  37. class P = native,
  38. class E = default_exception_policy
  39. >
  40. using safe_unsigned_range = safe_base<
  41. typename utility::unsigned_stored_type<Min, Max>,
  42. static_cast<typename utility::unsigned_stored_type<Min, Max> >(Min),
  43. static_cast<typename utility::unsigned_stored_type<Min, Max> >(Max),
  44. P,
  45. E
  46. >;
  47. } // safe_numerics
  48. } // boost
  49. #endif // BOOST_NUMERIC_SAFE_RANGE_HPP