]> git.lyx.org Git - lyx.git/blob - boost/boost/integer.hpp
ws change
[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 //   01 Apr 01  Modified to use new <boost/limits.hpp> header. (John Maddock)
13 //   30 Jul 00  Add typename syntax fix (Jens Maurer)
14 //   28 Aug 99  Initial version
15
16 #ifndef BOOST_INTEGER_HPP
17 #define BOOST_INTEGER_HPP
18
19 #include <boost/limits.hpp>
20
21 namespace boost
22 {
23
24   //  Helper templates  ------------------------------------------------------//
25
26   //  fast integers from least integers
27   //  int_fast_t<> works correctly for unsigned too, in spite of the name.
28   template< typename LeastInt >
29   struct int_fast_t { typedef LeastInt fast; }; // imps may specialize
30
31   //  convert category to type 
32   template< int Category > struct int_least_helper {}; // default is empty
33
34   //  specializatons: 1=long, 2=int, 3=short, 4=signed char,
35   //     6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned long
36   //  no specializations for 0 and 5: requests for a type > long are in error
37   template<> struct int_least_helper<1> { typedef long least; };
38   template<> struct int_least_helper<2> { typedef int least; };
39   template<> struct int_least_helper<3> { typedef short least; };
40   template<> struct int_least_helper<4> { typedef signed char least; };
41   template<> struct int_least_helper<6> { typedef unsigned long least; };
42   template<> struct int_least_helper<7> { typedef unsigned int least; };
43   template<> struct int_least_helper<8> { typedef unsigned short least; };
44   template<> struct int_least_helper<9> { typedef unsigned char least; };
45
46   //  integer templates specifying number of bits  ---------------------------//
47
48   //  signed
49   template< int Bits >   // bits (including sign) required
50   struct int_t 
51   {
52       typedef typename int_least_helper
53         <
54           (Bits-1 <= std::numeric_limits<long>::digits) +
55           (Bits-1 <= std::numeric_limits<int>::digits) +
56           (Bits-1 <= std::numeric_limits<short>::digits) +
57           (Bits-1 <= std::numeric_limits<signed char>::digits)
58         >::least  least;
59       typedef typename int_fast_t<least>::fast  fast;
60   };
61
62   //  unsigned
63   template< int Bits >   // bits required
64   struct uint_t 
65   {
66       typedef typename int_least_helper
67         < 
68           5 +
69           (Bits <= std::numeric_limits<unsigned long>::digits) +
70           (Bits <= std::numeric_limits<unsigned int>::digits) +
71           (Bits <= std::numeric_limits<unsigned short>::digits) +
72           (Bits <= std::numeric_limits<unsigned char>::digits)
73         >::least  least;
74       typedef typename int_fast_t<least>::fast  fast;
75       // int_fast_t<> works correctly for unsigned too, in spite of the name.
76   };
77
78 //  The same dispatching technique can be used to select types based on
79 //  values.  That will be added once boost::integer_traits is available.
80
81
82 } // namespace boost
83
84 #endif  // BOOST_INTEGER_HPP
85