source: NonGTP/Boost/boost/type_traits/integral_constant.hpp @ 857

Revision 857, 2.8 KB checked in by igarcia, 18 years ago (diff)
Line 
1//  (C) Copyright John Maddock 2005.
2//  Use, modification and distribution are subject to the
3//  Boost Software License, Version 1.0. (See accompanying file
4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef BOOST_TYPE_TRAITS_INTEGRAL_CONSTANT_HPP
7#define BOOST_TYPE_TRAITS_INTEGRAL_CONSTANT_HPP
8
9#include <boost/config.hpp>
10#include <boost/mpl/bool.hpp>
11#include <boost/mpl/integral_c.hpp>
12
13namespace boost{
14
15#if defined(BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS) || defined(__BORLANDC__)
16template <class T, int val>
17#else
18template <class T, T val>
19#endif
20struct integral_constant : public mpl::integral_c<T, val>
21{
22   //BOOST_STATIC_CONSTANT(T, value = val);
23   //typedef T value_type;
24   typedef integral_constant<T,val> type;
25
26#if 0
27   //
28   // everything that follows now, is MPL-compatibility code:
29   //
30   typedef ::boost::mpl::integral_c_tag tag;
31
32   // have to #ifdef here: some compilers don't like the 'val + 1' form (MSVC),
33   // while some other don't like 'value + 1' (Borland), and some don't like
34   // either
35#if BOOST_WORKAROUND(__EDG_VERSION__, <= 243)
36private:
37   BOOST_STATIC_CONSTANT(T, next_value = BOOST_MPL_AUX_STATIC_CAST(T, (val + 1)));
38   BOOST_STATIC_CONSTANT(T, prior_value = BOOST_MPL_AUX_STATIC_CAST(T, (val - 1)));
39public:
40   typedef integral_constant<T,next_value> next;
41   typedef integral_constant<T,prior_value> prior;
42#elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561)) \
43   || BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(502)) \
44   || BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(53800))
45   typedef integral_constant<T, ( BOOST_MPL_AUX_STATIC_CAST(T, (val + 1)) )> next;
46   typedef integral_constant<T, ( BOOST_MPL_AUX_STATIC_CAST(T, (val - 1)) )> prior;
47#else
48   typedef integral_constant<T, ( BOOST_MPL_AUX_STATIC_CAST(T, (value + 1)) )> next;
49   typedef integral_constant<T, ( BOOST_MPL_AUX_STATIC_CAST(T, (value - 1)) )> prior;
50#endif
51
52   // enables uniform function call syntax for families of overloaded
53   // functions that return objects of both arithmetic ('int', 'long',
54   // 'double', etc.) and wrapped integral types (for an example, see
55   // "mpl/example/power.cpp")
56   operator T() const { return static_cast<T>(this->value); }
57#endif
58};
59
60template<> struct integral_constant<bool,true> : public mpl::true_
61{
62#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
63   typedef mpl::true_ base_;
64   using base_::value;
65#endif
66   typedef integral_constant<bool,true> type;
67};
68template<> struct integral_constant<bool,false> : public mpl::false_
69{
70#if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
71   typedef mpl::false_ base_;
72   using base_::value;
73#endif
74   typedef integral_constant<bool,false> type;
75};
76
77typedef integral_constant<bool,true> true_type;
78typedef integral_constant<bool,false> false_type;
79
80}
81
82#endif
Note: See TracBrowser for help on using the repository browser.