int.hpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*=============================================================================
  2. Copyright (c) 2001-2012 Joel de Guzman
  3. Copyright (c) 2001-2011 Hartmut Kaiser
  4. Copyright (c) 2011 Bryce Lelbach
  5. Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. #if !defined(BOOST_SPIRIT_TEST_X3_INT_HPP)
  9. #define BOOST_SPIRIT_TEST_X3_INT_HPP
  10. #include <climits>
  11. #include <boost/detail/lightweight_test.hpp>
  12. #include <boost/spirit/home/x3/numeric/int.hpp>
  13. #include "test.hpp"
  14. ///////////////////////////////////////////////////////////////////////////////
  15. //
  16. // *** BEWARE PLATFORM DEPENDENT!!! ***
  17. // *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
  18. // *** Modify these constant strings when appropriate.
  19. //
  20. ///////////////////////////////////////////////////////////////////////////////
  21. static_assert(sizeof(long long) == 8, "unexpected long long size");
  22. #if INT_MAX != LLONG_MAX
  23. static_assert(sizeof(int) == 4, "unexpected int size");
  24. char const* max_int = "2147483647";
  25. char const* int_overflow = "2147483648";
  26. char const* min_int = "-2147483648";
  27. char const* int_underflow = "-2147483649";
  28. #else
  29. static_assert(sizeof(int) == 8, "unexpected int size");
  30. char const* max_int = "9223372036854775807";
  31. char const* int_overflow = "9223372036854775808";
  32. char const* min_int = "-9223372036854775808";
  33. char const* int_underflow = "-9223372036854775809";
  34. #endif
  35. char const* max_long_long = "9223372036854775807";
  36. char const* long_long_overflow = "9223372036854775808";
  37. char const* min_long_long = "-9223372036854775808";
  38. char const* long_long_underflow = "-9223372036854775809";
  39. ///////////////////////////////////////////////////////////////////////////////
  40. // A custom int type
  41. struct custom_int
  42. {
  43. int n;
  44. custom_int() : n(0) {}
  45. explicit custom_int(int n_) : n(n_) {}
  46. custom_int& operator=(int n_) { n = n_; return *this; }
  47. friend bool operator==(custom_int a, custom_int b) { return a.n == b.n; }
  48. friend bool operator==(custom_int a, int b) { return a.n == b; }
  49. friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
  50. friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
  51. friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
  52. };
  53. #endif