]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/include/boost/integer.hpp
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
28a1325f2fc201c983237ba942efe6d099f8c2ab
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / include / boost / integer.hpp
1 //  boost integer.hpp header file  -------------------------------------------//\r
2 \r
3 //  Copyright Beman Dawes and Daryle Walker 1999.  Distributed under the Boost\r
4 //  Software License, Version 1.0. (See accompanying file\r
5 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)\r
6 \r
7 //  See http://www.boost.org/libs/integer for documentation.\r
8 \r
9 //  Revision History\r
10 //   22 Sep 01  Added value-based integer templates. (Daryle Walker)\r
11 //   01 Apr 01  Modified to use new <boost/limits.hpp> header. (John Maddock)\r
12 //   30 Jul 00  Add typename syntax fix (Jens Maurer)\r
13 //   28 Aug 99  Initial version\r
14 \r
15 #ifndef BOOST_INTEGER_HPP\r
16 #define BOOST_INTEGER_HPP\r
17 \r
18 #include <boost/integer_fwd.hpp>  // self include\r
19 \r
20 #include <boost/integer_traits.hpp>  // for boost::::boost::integer_traits\r
21 #include <boost/limits.hpp>          // for ::std::numeric_limits\r
22 #include <boost/cstdint.hpp>         // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T\r
23 \r
24 //\r
25 // We simply cannot include this header on gcc without getting copious warnings of the kind:\r
26 //\r
27 // boost/integer.hpp:77:30: warning: use of C99 long long integer constant\r
28 //\r
29 // And yet there is no other reasonable implementation, so we declare this a system header\r
30 // to suppress these warnings.\r
31 //\r
32 #if defined(__GNUC__) && (__GNUC__ >= 4)\r
33 #pragma GCC system_header\r
34 #endif\r
35 \r
36 namespace boost\r
37 {\r
38 \r
39   //  Helper templates  ------------------------------------------------------//\r
40 \r
41   //  fast integers from least integers\r
42   //  int_fast_t<> works correctly for unsigned too, in spite of the name.\r
43   template< typename LeastInt >\r
44   struct int_fast_t \r
45   { \r
46      typedef LeastInt fast; \r
47      typedef fast     type;\r
48   }; // imps may specialize\r
49 \r
50   namespace detail{\r
51 \r
52   //  convert category to type \r
53   template< int Category > struct int_least_helper {}; // default is empty\r
54 \r
55   //  specializatons: 1=long, 2=int, 3=short, 4=signed char,\r
56   //     6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char\r
57   //  no specializations for 0 and 5: requests for a type > long are in error\r
58 #ifdef BOOST_HAS_LONG_LONG\r
59   template<> struct int_least_helper<1> { typedef boost::long_long_type least; };\r
60 #endif\r
61   template<> struct int_least_helper<2> { typedef long least; };\r
62   template<> struct int_least_helper<3> { typedef int least; };\r
63   template<> struct int_least_helper<4> { typedef short least; };\r
64   template<> struct int_least_helper<5> { typedef signed char least; };\r
65 #ifdef BOOST_HAS_LONG_LONG\r
66   template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; };\r
67 #endif\r
68   template<> struct int_least_helper<7> { typedef unsigned long least; };\r
69   template<> struct int_least_helper<8> { typedef unsigned int least; };\r
70   template<> struct int_least_helper<9> { typedef unsigned short least; };\r
71   template<> struct int_least_helper<10> { typedef unsigned char least; };\r
72 \r
73   template <int Bits>\r
74   struct exact_signed_base_helper{};\r
75   template <int Bits>\r
76   struct exact_unsigned_base_helper{};\r
77 \r
78   template <> struct exact_signed_base_helper<sizeof(signed char)* CHAR_BIT> { typedef signed char exact; };\r
79   template <> struct exact_unsigned_base_helper<sizeof(unsigned char)* CHAR_BIT> { typedef unsigned char exact; };\r
80 #if USHRT_MAX != UCHAR_MAX\r
81   template <> struct exact_signed_base_helper<sizeof(short)* CHAR_BIT> { typedef short exact; };\r
82   template <> struct exact_unsigned_base_helper<sizeof(unsigned short)* CHAR_BIT> { typedef unsigned short exact; };\r
83 #endif\r
84 #if UINT_MAX != USHRT_MAX\r
85   template <> struct exact_signed_base_helper<sizeof(int)* CHAR_BIT> { typedef int exact; };\r
86   template <> struct exact_unsigned_base_helper<sizeof(unsigned int)* CHAR_BIT> { typedef unsigned int exact; };\r
87 #endif\r
88 #if ULONG_MAX != UINT_MAX\r
89   template <> struct exact_signed_base_helper<sizeof(long)* CHAR_BIT> { typedef long exact; };\r
90   template <> struct exact_unsigned_base_helper<sizeof(unsigned long)* CHAR_BIT> { typedef unsigned long exact; };\r
91 #endif\r
92 #if defined(BOOST_HAS_LONG_LONG) &&\\r
93    ((defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) ||\\r
94     (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) ||\\r
95     (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) ||\\r
96     (defined(_ULLONG_MAX) && (_ULLONG_MAX != ULONG_MAX)))\r
97   template <> struct exact_signed_base_helper<sizeof(boost::long_long_type)* CHAR_BIT> { typedef boost::long_long_type exact; };\r
98   template <> struct exact_unsigned_base_helper<sizeof(boost::ulong_long_type)* CHAR_BIT> { typedef boost::ulong_long_type exact; };\r
99 #endif\r
100 \r
101 \r
102   } // namespace detail\r
103 \r
104   //  integer templates specifying number of bits  ---------------------------//\r
105 \r
106   //  signed\r
107   template< int Bits >   // bits (including sign) required\r
108   struct int_t : public detail::exact_signed_base_helper<Bits>\r
109   {\r
110       typedef typename detail::int_least_helper\r
111         <\r
112 #ifdef BOOST_HAS_LONG_LONG\r
113           (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +\r
114 #else\r
115            1 +\r
116 #endif\r
117           (Bits-1 <= ::std::numeric_limits<long>::digits) +\r
118           (Bits-1 <= ::std::numeric_limits<int>::digits) +\r
119           (Bits-1 <= ::std::numeric_limits<short>::digits) +\r
120           (Bits-1 <= ::std::numeric_limits<signed char>::digits)\r
121         >::least  least;\r
122       typedef typename int_fast_t<least>::type  fast;\r
123   };\r
124 \r
125   //  unsigned\r
126   template< int Bits >   // bits required\r
127   struct uint_t : public detail::exact_unsigned_base_helper<Bits>\r
128   {\r
129 #if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T)\r
130      // It's really not clear why this workaround should be needed... shrug I guess!  JM\r
131      BOOST_STATIC_CONSTANT(int, s = \r
132            6 +\r
133           (Bits <= ::std::numeric_limits<unsigned long>::digits) +\r
134           (Bits <= ::std::numeric_limits<unsigned int>::digits) +\r
135           (Bits <= ::std::numeric_limits<unsigned short>::digits) +\r
136           (Bits <= ::std::numeric_limits<unsigned char>::digits));\r
137      typedef typename detail::int_least_helper< ::boost::uint_t<Bits>::s>::least least;\r
138 #else\r
139       typedef typename detail::int_least_helper\r
140         < \r
141           5 +\r
142 #ifdef BOOST_HAS_LONG_LONG\r
143           (Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +\r
144 #else\r
145            1 +\r
146 #endif\r
147           (Bits <= ::std::numeric_limits<unsigned long>::digits) +\r
148           (Bits <= ::std::numeric_limits<unsigned int>::digits) +\r
149           (Bits <= ::std::numeric_limits<unsigned short>::digits) +\r
150           (Bits <= ::std::numeric_limits<unsigned char>::digits)\r
151         >::least  least;\r
152 #endif\r
153       typedef typename int_fast_t<least>::type  fast;\r
154       // int_fast_t<> works correctly for unsigned too, in spite of the name.\r
155   };\r
156 \r
157   //  integer templates specifying extreme value  ----------------------------//\r
158 \r
159   //  signed\r
160 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
161   template< boost::long_long_type MaxValue >   // maximum value to require support\r
162 #else\r
163   template< long MaxValue >   // maximum value to require support\r
164 #endif\r
165   struct int_max_value_t \r
166   {\r
167       typedef typename detail::int_least_helper\r
168         <\r
169 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
170           (MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +\r
171 #else\r
172            1 +\r
173 #endif\r
174           (MaxValue <= ::boost::integer_traits<long>::const_max) +\r
175           (MaxValue <= ::boost::integer_traits<int>::const_max) +\r
176           (MaxValue <= ::boost::integer_traits<short>::const_max) +\r
177           (MaxValue <= ::boost::integer_traits<signed char>::const_max)\r
178         >::least  least;\r
179       typedef typename int_fast_t<least>::type  fast;\r
180   };\r
181 \r
182 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
183   template< boost::long_long_type MinValue >   // minimum value to require support\r
184 #else\r
185   template< long MinValue >   // minimum value to require support\r
186 #endif\r
187   struct int_min_value_t \r
188   {\r
189       typedef typename detail::int_least_helper\r
190         <\r
191 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
192           (MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +\r
193 #else\r
194            1 +\r
195 #endif\r
196           (MinValue >= ::boost::integer_traits<long>::const_min) +\r
197           (MinValue >= ::boost::integer_traits<int>::const_min) +\r
198           (MinValue >= ::boost::integer_traits<short>::const_min) +\r
199           (MinValue >= ::boost::integer_traits<signed char>::const_min)\r
200         >::least  least;\r
201       typedef typename int_fast_t<least>::type  fast;\r
202   };\r
203 \r
204   //  unsigned\r
205 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
206   template< boost::ulong_long_type MaxValue >   // minimum value to require support\r
207 #else\r
208   template< unsigned long MaxValue >   // minimum value to require support\r
209 #endif\r
210   struct uint_value_t \r
211   {\r
212 #if (defined(__BORLANDC__) || defined(__CODEGEAR__))\r
213      // It's really not clear why this workaround should be needed... shrug I guess!  JM\r
214 #if defined(BOOST_NO_INTEGRAL_INT64_T)\r
215       BOOST_STATIC_CONSTANT(unsigned, which = \r
216            6 +\r
217           (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +\r
218           (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +\r
219           (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +\r
220           (MaxValue <= ::boost::integer_traits<unsigned char>::const_max));\r
221       typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;\r
222 #else // BOOST_NO_INTEGRAL_INT64_T\r
223       BOOST_STATIC_CONSTANT(unsigned, which = \r
224            5 +\r
225           (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +\r
226           (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +\r
227           (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +\r
228           (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +\r
229           (MaxValue <= ::boost::integer_traits<unsigned char>::const_max));\r
230       typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;\r
231 #endif // BOOST_NO_INTEGRAL_INT64_T\r
232 #else\r
233       typedef typename detail::int_least_helper\r
234         < \r
235           5 +\r
236 #if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)\r
237           (MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +\r
238 #else\r
239            1 +\r
240 #endif\r
241           (MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +\r
242           (MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +\r
243           (MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +\r
244           (MaxValue <= ::boost::integer_traits<unsigned char>::const_max)\r
245         >::least  least;\r
246 #endif\r
247       typedef typename int_fast_t<least>::type  fast;\r
248   };\r
249 \r
250 \r
251 } // namespace boost\r
252 \r
253 #endif  // BOOST_INTEGER_HPP\r