1 // (C) Copyright John Maddock 2015.
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/detail/workaround.hpp>
12 #if (BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \
13 || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \
14 || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840)) \
15 || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \
16 || BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) )
22 template <bool B> struct bool_;
23 template <class I, I val> struct integral_c;
24 struct integral_c_tag;
32 template <bool B> struct bool_;
33 template <class I, I val> struct integral_c;
34 struct integral_c_tag;
42 using ::mpl_::integral_c;
43 using ::mpl_::integral_c_tag;
51 template <class T, T val>
52 struct integral_constant
54 typedef mpl::integral_c_tag tag;
56 typedef integral_constant<T, val> type;
57 static const T value = val;
59 // This helper function is just to disable type-punning
63 static U& dereference(U* p) { return *p; }
65 operator const mpl::integral_c<T, val>& ()const
67 static const char data[sizeof(long)] = { 0 };
68 return dereference(reinterpret_cast<const mpl::integral_c<T, val>*>(&data));
70 BOOST_CONSTEXPR operator T()const { return val; }
73 template <class T, T val>
74 T const integral_constant<T, val>::value;
77 struct integral_constant<bool, val>
79 typedef mpl::integral_c_tag tag;
80 typedef bool value_type;
81 typedef integral_constant<bool, val> type;
82 static const bool value = val;
84 // This helper function is just to disable type-punning
88 static T& dereference(T* p) { return *p; }
90 operator const mpl::bool_<val>& ()const
92 static const char data = 0;
93 return dereference(reinterpret_cast<const mpl::bool_<val>*>(&data));
95 BOOST_CONSTEXPR operator bool()const { return val; }
99 bool const integral_constant<bool, val>::value;
101 typedef integral_constant<bool, true> true_type;
102 typedef integral_constant<bool, false> false_type;