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/detail/lightweight_test.hpp>
14 #include <boost/spirit/home/x3/numeric/int.hpp>
15 #include "test.hpp"
16 
17 ///////////////////////////////////////////////////////////////////////////////
18 //
19 //  *** BEWARE PLATFORM DEPENDENT!!! ***
20 //  *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
21 //  *** Modify these constant strings when appropriate.
22 //
23 ///////////////////////////////////////////////////////////////////////////////
24 
25     static_assert(sizeof(long long) == 8, "unexpected long long size");
26 
27 #if INT_MAX != LLONG_MAX
28     static_assert(sizeof(int) == 4, "unexpected int size");
29     char const* max_int = "2147483647";
30     char const* int_overflow = "2147483648";
31     char const* min_int = "-2147483648";
32     char const* int_underflow = "-2147483649";
33 #else
34     static_assert(sizeof(int) == 8, "unexpected int size");
35     char const* max_int = "9223372036854775807";
36     char const* int_overflow = "9223372036854775808";
37     char const* min_int = "-9223372036854775808";
38     char const* int_underflow = "-9223372036854775809";
39 #endif
40 
41     char const* max_long_long = "9223372036854775807";
42     char const* long_long_overflow = "9223372036854775808";
43     char const* min_long_long = "-9223372036854775808";
44     char const* long_long_underflow = "-9223372036854775809";
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 // A custom int type
48 struct custom_int
49 {
50     int n;
custom_intcustom_int51     custom_int() : n(0) {}
custom_intcustom_int52     explicit custom_int(int n_) : n(n_) {}
operator =custom_int53     custom_int& operator=(int n_) { n = n_; return *this; }
operator ==(custom_int a,custom_int b)54     friend bool operator==(custom_int a, custom_int b) { return a.n == b.n; }
operator ==(custom_int a,int b)55     friend bool operator==(custom_int a, int b) { return a.n == b; }
operator *(custom_int a,custom_int b)56     friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
operator +(custom_int a,custom_int b)57     friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
operator -(custom_int a,custom_int b)58     friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
59 };
60 
61 #endif
62