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