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)
6 #ifndef BOOST_TYPE_TRAITS_INTEGRAL_CONSTANT_HPP
7 #define BOOST_TYPE_TRAITS_INTEGRAL_CONSTANT_HPP
9 #include <boost/config.hpp>
10 #include <boost/mpl/bool.hpp>
11 #include <boost/mpl/integral_c.hpp>
15 #if defined(BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS) || defined(__BORLANDC__)
16 template <class T, int val>
18 template <class T, T val>
20 struct integral_constant : public mpl::integral_c<T, val>
22 //BOOST_STATIC_CONSTANT(T, value = val);
23 //typedef T value_type;
24 typedef integral_constant<T,val> type;
28 // everything that follows now, is MPL-compatibility code:
30 typedef ::boost::mpl::integral_c_tag tag;
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
35 #if BOOST_WORKAROUND(__EDG_VERSION__, <= 243)
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)));
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;
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;
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); }
60 template<> struct integral_constant<bool,true> : public mpl::true_
62 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
63 typedef mpl::true_ base_;
66 typedef integral_constant<bool,true> type;
68 template<> struct integral_constant<bool,false> : public mpl::false_
70 #if BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
71 typedef mpl::false_ base_;
74 typedef integral_constant<bool,false> type;
77 typedef integral_constant<bool,true> true_type;
78 typedef integral_constant<bool,false> false_type;