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