]> git.lyx.org Git - lyx.git/blob - boost/boost/integer.hpp
complie fix
[lyx.git] / boost / boost / integer.hpp
1 //  boost integer.hpp header file  -------------------------------------------//
2
3 //  (C) Copyright Beman Dawes 1999. Permission to copy, use, modify, sell
4 //  and distribute this software is granted provided this copyright
5 //  notice appears in all copies. This software is provided "as is" without
6 //  express or implied warranty, and with no claim as to its suitability for
7 //  any purpose.
8
9 //  See http://www.boost.org for most recent version including documentation.
10
11 //  Revision History
12 //   22 Sep 01  Added value-based integer templates. (Daryle Walker)
13 //   01 Apr 01  Modified to use new <boost/limits.hpp> header. (John Maddock)
14 //   30 Jul 00  Add typename syntax fix (Jens Maurer)
15 //   28 Aug 99  Initial version
16
17 #ifndef BOOST_INTEGER_HPP
18 #define BOOST_INTEGER_HPP
19
20 #include <boost/integer_fwd.hpp>  // self include
21
22 #include <boost/integer_traits.hpp>  // for boost::integer_traits
23 #include <boost/limits.hpp>          // for std::numeric_limits
24
25 namespace boost
26 {
27
28   //  Helper templates  ------------------------------------------------------//
29
30   //  fast integers from least integers
31   //  int_fast_t<> works correctly for unsigned too, in spite of the name.
32   template< typename LeastInt >
33   struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
34
35   //  convert category to type 
36   template< int Category > struct int_least_helper {}; // default is empty
37
38   //  specializatons: 1=long, 2=int, 3=short, 4=signed char,
39   //     6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
40   //  no specializations for 0 and 5: requests for a type > long are in error
41   template<> struct int_least_helper<1> { typedef long least; };
42   template<> struct int_least_helper<2> { typedef int least; };
43   template<> struct int_least_helper<3> { typedef short least; };
44   template<> struct int_least_helper<4> { typedef signed char least; };
45   template<> struct int_least_helper<6> { typedef unsigned long least; };
46   template<> struct int_least_helper<7> { typedef unsigned int least; };
47   template<> struct int_least_helper<8> { typedef unsigned short least; };
48   template<> struct int_least_helper<9> { typedef unsigned char least; };
49
50   //  integer templates specifying number of bits  ---------------------------//
51
52   //  signed
53   template< int Bits >   // bits (including sign) required
54   struct int_t 
55   {
56       typedef typename int_least_helper
57         <
58           (Bits-1 <= std::numeric_limits<long>::digits) +
59           (Bits-1 <= std::numeric_limits<int>::digits) +
60           (Bits-1 <= std::numeric_limits<short>::digits) +
61           (Bits-1 <= std::numeric_limits<signed char>::digits)
62         >::least  least;
63       typedef typename int_fast_t<least>::fast  fast;
64   };
65
66   //  unsigned
67   template< int Bits >   // bits required
68   struct uint_t 
69   {
70       typedef typename int_least_helper
71         < 
72           5 +
73           (Bits <= std::numeric_limits<unsigned long>::digits) +
74           (Bits <= std::numeric_limits<unsigned int>::digits) +
75           (Bits <= std::numeric_limits<unsigned short>::digits) +
76           (Bits <= std::numeric_limits<unsigned char>::digits)
77         >::least  least;
78       typedef typename int_fast_t<least>::fast  fast;
79       // int_fast_t<> works correctly for unsigned too, in spite of the name.
80   };
81
82   //  integer templates specifying extreme value  ----------------------------//
83
84   //  signed
85   template< long MaxValue >   // maximum value to require support
86   struct int_max_value_t 
87   {
88       typedef typename int_least_helper
89         <
90           (MaxValue <= integer_traits<long>::const_max) +
91           (MaxValue <= integer_traits<int>::const_max) +
92           (MaxValue <= integer_traits<short>::const_max) +
93           (MaxValue <= integer_traits<signed char>::const_max)
94         >::least  least;
95       typedef typename int_fast_t<least>::fast  fast;
96   };
97
98   template< long MinValue >   // minimum value to require support
99   struct int_min_value_t 
100   {
101       typedef typename int_least_helper
102         <
103           (MinValue >= integer_traits<long>::const_min) +
104           (MinValue >= integer_traits<int>::const_min) +
105           (MinValue >= integer_traits<short>::const_min) +
106           (MinValue >= integer_traits<signed char>::const_min)
107         >::least  least;
108       typedef typename int_fast_t<least>::fast  fast;
109   };
110
111   //  unsigned
112   template< unsigned long Value >   // maximum value to require support
113   struct uint_value_t 
114   {
115       typedef typename int_least_helper
116         < 
117           5 +
118           (Value <= integer_traits<unsigned long>::const_max) +
119           (Value <= integer_traits<unsigned int>::const_max) +
120           (Value <= integer_traits<unsigned short>::const_max) +
121           (Value <= integer_traits<unsigned char>::const_max)
122         >::least  least;
123       typedef typename int_fast_t<least>::fast  fast;
124   };
125
126
127 } // namespace boost
128
129 #endif  // BOOST_INTEGER_HPP