1 //
2 //! Copyright (c) 2011
3 //! Brandon Kohn
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 //
9
10 #include <boost/operators.hpp>
11 #include <boost/numeric/conversion/cast.hpp>
12 #include <boost/preprocessor/control/iif.hpp>
13 #include <boost/preprocessor/comparison/less.hpp>
14 #include <boost/preprocessor/comparison/not_equal.hpp>
15 #include <boost/preprocessor/repetition/for.hpp>
16 #include <boost/preprocessor/tuple/elem.hpp>
17 #include <boost/preprocessor/seq/elem.hpp>
18 #include <boost/preprocessor/seq/size.hpp>
19 #include <boost/test/minimal.hpp>
20
21 //! Generate default traits for the specified source and target.
22 #define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS(r, state) \
23 template <> \
24 struct numeric_cast_traits< \
25 BOOST_PP_SEQ_ELEM( BOOST_PP_TUPLE_ELEM(4,0,state) \
26 , BOOST_PP_TUPLE_ELEM(4,3,state) ) \
27 , BOOST_PP_TUPLE_ELEM(4,2,state)> \
28 { \
29 typedef def_overflow_handler overflow_policy; \
30 typedef UseInternalRangeChecker range_checking_policy; \
31 typedef Trunc<BOOST_PP_TUPLE_ELEM(4,2,state)> rounding_policy; \
32 }; \
33 /***/
34
35 #define BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL(r, state) \
36 BOOST_PP_LESS \
37 ( \
38 BOOST_PP_TUPLE_ELEM(4,0,state) \
39 , BOOST_PP_TUPLE_ELEM(4,1,state) \
40 ) \
41 /***/
42
43 #define BOOST_NUMERIC_CONVERSION_INC_OP(r, state) \
44 ( \
45 BOOST_PP_INC(BOOST_PP_TUPLE_ELEM(4,0,state)) \
46 , BOOST_PP_TUPLE_ELEM(4,1,state) \
47 , BOOST_PP_TUPLE_ELEM(4,2,state) \
48 , BOOST_PP_TUPLE_ELEM(4,3,state) \
49 ) \
50 /***/
51
52 #define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP(r, state) \
53 BOOST_PP_FOR \
54 ( \
55 ( \
56 0 \
57 , BOOST_PP_TUPLE_ELEM(4,1,state) \
58 , BOOST_PP_SEQ_ELEM(BOOST_PP_TUPLE_ELEM(4,0,state),BOOST_PP_TUPLE_ELEM(4,2,state)) \
59 , BOOST_PP_TUPLE_ELEM(4,2,state) \
60 ) \
61 , BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL \
62 , BOOST_NUMERIC_CONVERSION_INC_OP \
63 , BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS \
64 ) \
65 /***/
66
67 #define BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS(types) \
68 BOOST_PP_FOR \
69 ( \
70 (0,BOOST_PP_SEQ_SIZE(types),types,_) \
71 , BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL \
72 , BOOST_NUMERIC_CONVERSION_INC_OP \
73 , BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP \
74 ) \
75 /***/
76
77 namespace boost { namespace numeric {
78 #if !defined( BOOST_NO_INT64_T )
79 //! Generate the specializations for the built-in types.
80 BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
81 (
82 (char)
83 (boost::int8_t)
84 (boost::uint8_t)
85 (boost::int16_t)
86 (boost::uint16_t)
87 (boost::int32_t)
88 (boost::uint32_t)
89 (boost::int64_t)
90 (boost::uint64_t)
91 (float)
92 (double)
93 (long double)
94 )
95 #else
96 BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
97 (
98 (char)
99 (boost::int8_t)
100 (boost::uint8_t)
101 (boost::int16_t)
102 (boost::uint16_t)
103 (boost::int32_t)
104 (boost::uint32_t)
105 (float)
106 (double)
107 (long double)
108 )
109 #endif
110 }}//namespace boost::numeric;
111
test_main(int argc,char * argv[])112 int test_main( int argc, char * argv[] )
113 {
114 //! This test should not compile.
115 return 1;
116 }
117
118 #undef BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
119 #undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP
120 #undef BOOST_NUMERIC_CONVERSION_INC_OP
121 #undef BOOST_NUMERIC_CONVERSION_TUPLE_SENTINAL
122 #undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS
123