diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:33:54 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2016-10-06 10:36:09 +0900 |
commit | d9ec475d945d3035377a0d89ed42e382d8988891 (patch) | |
tree | 34aff2cee4b209906243ab5499d61f3edee2982f /boost/type_traits/integral_constant.hpp | |
parent | 71d216b90256936a9638f325af9bc69d720e75de (diff) | |
download | boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.gz boost-d9ec475d945d3035377a0d89ed42e382d8988891.tar.bz2 boost-d9ec475d945d3035377a0d89ed42e382d8988891.zip |
Imported Upstream version 1.60.0
Change-Id: Ie709530d6d5841088ceaba025cbe175a4ef43050
Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/type_traits/integral_constant.hpp')
-rw-r--r-- | boost/type_traits/integral_constant.hpp | 107 |
1 files changed, 87 insertions, 20 deletions
diff --git a/boost/type_traits/integral_constant.hpp b/boost/type_traits/integral_constant.hpp index c6847715e0..ae2448d070 100644 --- a/boost/type_traits/integral_constant.hpp +++ b/boost/type_traits/integral_constant.hpp @@ -1,4 +1,4 @@ -// (C) Copyright John Maddock 2005. +// (C) Copyright John Maddock 2015. // Use, modification and distribution are subject to the // Boost Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -7,32 +7,99 @@ #define BOOST_TYPE_TRAITS_INTEGRAL_CONSTANT_HPP #include <boost/config.hpp> -#include <boost/mpl/bool.hpp> -#include <boost/mpl/integral_c.hpp> +#include <boost/detail/workaround.hpp> + +#if (BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1400)) \ + || BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) \ + || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x840)) \ + || BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3202)) \ + || BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, BOOST_TESTED_AT(810)) ) + namespace boost{ + namespace mpl + { + template <bool B> struct bool_; + template <class I, I val> struct integral_c; + struct integral_c_tag; + } +} -#if defined(BOOST_NO_DEPENDENT_TYPES_IN_TEMPLATE_VALUE_PARAMETERS) || defined(__BORLANDC__) -template <class T, int val> #else -template <class T, T val> -#endif -struct integral_constant : public mpl::integral_c<T, val> -{ - typedef integral_constant<T,val> type; -}; -template<> struct integral_constant<bool,true> : public mpl::true_ -{ - typedef integral_constant<bool,true> type; -}; -template<> struct integral_constant<bool,false> : public mpl::false_ +namespace mpl_{ + + template <bool B> struct bool_; + template <class I, I val> struct integral_c; + struct integral_c_tag; +} + +namespace boost { - typedef integral_constant<bool,false> type; -}; + namespace mpl + { + using ::mpl_::bool_; + using ::mpl_::integral_c; + using ::mpl_::integral_c_tag; + } +} + +#endif + +namespace boost{ + + template <class T, T val> + struct integral_constant + { + typedef mpl::integral_c_tag tag; + typedef T value_type; + typedef integral_constant<T, val> type; + static const T value = val; + // + // This helper function is just to disable type-punning + // warnings from GCC: + // + template <class U> + static U& dereference(U* p) { return *p; } + + operator const mpl::integral_c<T, val>& ()const + { + static const char data[sizeof(long)] = { 0 }; + return dereference(reinterpret_cast<const mpl::integral_c<T, val>*>(&data)); + } + BOOST_CONSTEXPR operator T()const { return val; } + }; + + template <class T, T val> + T const integral_constant<T, val>::value; + + template <bool val> + struct integral_constant<bool, val> + { + typedef mpl::integral_c_tag tag; + typedef bool value_type; + typedef integral_constant<bool, val> type; + static const bool value = val; + // + // This helper function is just to disable type-punning + // warnings from GCC: + // + template <class T> + static T& dereference(T* p) { return *p; } + + operator const mpl::bool_<val>& ()const + { + static const char data = 0; + return dereference(reinterpret_cast<const mpl::bool_<val>*>(&data)); + } + BOOST_CONSTEXPR operator bool()const { return val; } + }; + + template <bool val> + bool const integral_constant<bool, val>::value; -typedef integral_constant<bool,true> true_type; -typedef integral_constant<bool,false> false_type; + typedef integral_constant<bool, true> true_type; + typedef integral_constant<bool, false> false_type; } |