1 #ifndef BOOST_TYPE_TRAITS_DETAIL_COMMON_ARITHMETIC_TYPE_HPP_INCLUDED
2 #define BOOST_TYPE_TRAITS_DETAIL_COMMON_ARITHMETIC_TYPE_HPP_INCLUDED
5 // Copyright 2015 Peter Dimov
7 // Distributed under the Boost Software License, Version 1.0.
8 // See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt
12 #include <boost/config.hpp>
17 namespace type_traits_detail
20 template<int I> struct arithmetic_type;
22 // Types bool, char, char16_t, char32_t, wchar_t,
23 // and the signed and unsigned integer types are
24 // collectively called integral types
26 template<> struct arithmetic_type<1>
29 typedef char (&result_type) [1];
32 template<> struct arithmetic_type<2>
35 typedef char (&result_type) [2];
38 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
40 template<> struct arithmetic_type<3>
43 typedef char (&result_type) [3];
48 // There are five standard signed integer types:
49 // "signed char", "short int", "int", "long int", and "long long int".
51 template<> struct arithmetic_type<4>
53 typedef signed char type;
54 typedef char (&result_type) [4];
57 template<> struct arithmetic_type<5>
60 typedef char (&result_type) [5];
63 template<> struct arithmetic_type<6>
66 typedef char (&result_type) [6];
69 template<> struct arithmetic_type<7>
72 typedef char (&result_type) [7];
75 template<> struct arithmetic_type<8>
77 typedef boost::long_long_type type;
78 typedef char (&result_type) [8];
81 // For each of the standard signed integer types, there exists a corresponding
82 // (but different) standard unsigned integer type: "unsigned char", "unsigned short int",
83 // "unsigned int", "unsigned long int", and "unsigned long long int"
85 template<> struct arithmetic_type<9>
87 typedef unsigned char type;
88 typedef char (&result_type) [9];
91 template<> struct arithmetic_type<10>
93 typedef unsigned short type;
94 typedef char (&result_type) [10];
97 template<> struct arithmetic_type<11>
99 typedef unsigned int type;
100 typedef char (&result_type) [11];
103 template<> struct arithmetic_type<12>
105 typedef unsigned long type;
106 typedef char (&result_type) [12];
109 template<> struct arithmetic_type<13>
111 typedef boost::ulong_long_type type;
112 typedef char (&result_type) [13];
115 // There are three floating point types: float, double, and long double.
117 template<> struct arithmetic_type<14>
120 typedef char (&result_type) [14];
123 template<> struct arithmetic_type<15>
126 typedef char (&result_type) [15];
129 template<> struct arithmetic_type<16>
131 typedef long double type;
132 typedef char (&result_type) [16];
135 #if !defined( BOOST_NO_CXX11_CHAR16_T )
137 template<> struct arithmetic_type<17>
139 typedef char16_t type;
140 typedef char (&result_type) [17];
145 #if !defined( BOOST_NO_CXX11_CHAR32_T )
147 template<> struct arithmetic_type<18>
149 typedef char32_t type;
150 typedef char (&result_type) [18];
155 #if defined( BOOST_HAS_INT128 )
157 template<> struct arithmetic_type<19>
159 typedef boost::int128_type type;
160 typedef char (&result_type) [19];
163 template<> struct arithmetic_type<20>
165 typedef boost::uint128_type type;
166 typedef char (&result_type) [20];
171 template<class T, class U> class common_arithmetic_type
175 static arithmetic_type<1>::result_type select( arithmetic_type<1>::type );
176 static arithmetic_type<2>::result_type select( arithmetic_type<2>::type );
177 #ifndef BOOST_NO_INTRINSIC_WCHAR_T
178 static arithmetic_type<3>::result_type select( arithmetic_type<3>::type );
180 static arithmetic_type<4>::result_type select( arithmetic_type<4>::type );
181 static arithmetic_type<5>::result_type select( arithmetic_type<5>::type );
182 static arithmetic_type<6>::result_type select( arithmetic_type<6>::type );
183 static arithmetic_type<7>::result_type select( arithmetic_type<7>::type );
184 static arithmetic_type<8>::result_type select( arithmetic_type<8>::type );
185 static arithmetic_type<9>::result_type select( arithmetic_type<9>::type );
186 static arithmetic_type<10>::result_type select( arithmetic_type<10>::type );
187 static arithmetic_type<11>::result_type select( arithmetic_type<11>::type );
188 static arithmetic_type<12>::result_type select( arithmetic_type<12>::type );
189 static arithmetic_type<13>::result_type select( arithmetic_type<13>::type );
190 static arithmetic_type<14>::result_type select( arithmetic_type<14>::type );
191 static arithmetic_type<15>::result_type select( arithmetic_type<15>::type );
192 static arithmetic_type<16>::result_type select( arithmetic_type<16>::type );
194 #if !defined( BOOST_NO_CXX11_CHAR16_T )
195 static arithmetic_type<17>::result_type select( arithmetic_type<17>::type );
198 #if !defined( BOOST_NO_CXX11_CHAR32_T )
199 static arithmetic_type<18>::result_type select( arithmetic_type<18>::type );
202 #if defined( BOOST_HAS_INT128 )
203 static arithmetic_type<19>::result_type select( arithmetic_type<19>::type );
204 static arithmetic_type<20>::result_type select( arithmetic_type<20>::type );
211 typedef typename arithmetic_type< sizeof(select( cond()? T(): U() )) >::type type;
214 } // namespace type_traits_detail
218 #endif // #ifndef BOOST_TYPE_TRAITS_DETAIL_COMMON_ARITHMETIC_TYPE_HPP_INCLUDED