From 90fca0f64b4bfeb6d12eac2f15822c71f31dc66a Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 31 Jan 2015 09:58:35 +0000 Subject: [PATCH] Reorganise #includes to reduce dependencies - only legacy compilers should depend on anything other than Boost.Config now. --- include/boost/type_traits/common_type.hpp | 60 ++++++++++------------- 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/include/boost/type_traits/common_type.hpp b/include/boost/type_traits/common_type.hpp index b52ff16..03f9bd9 100644 --- a/include/boost/type_traits/common_type.hpp +++ b/include/boost/type_traits/common_type.hpp @@ -10,6 +10,7 @@ #define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP #include +#include #if defined(__SUNPRO_CC) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF @@ -18,40 +19,28 @@ # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF #endif +#ifdef __GNUC__ +// All supported GCC versions (and emulations thereof) support __typeof__ +#define BOOST_COMMON_TYPE_USE_TYPEOF +#endif + //----------------------------------------------------------------------------// #if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_COMMON_TYPE_ARITY) #define BOOST_COMMON_TYPE_ARITY 3 #endif //----------------------------------------------------------------------------// -#if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) -#include // boost wonders never cease! -#endif - -//----------------------------------------------------------------------------// -#ifndef BOOST_NO_CXX11_STATIC_ASSERT -#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG) -#elif defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) -#include -#include -#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) \ - BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES) -#else -#include -#define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND) -#endif - -#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || !defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT) -#define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type" -#endif - -#if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) -#include -#include -#endif -#include +#if !defined(BOOST_NO_CXX11_DECLTYPE) #include +#elif defined(BOOST_COMMON_TYPE_USE_TYPEOF) #include +#elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) +#include +#else +#include // boost wonders never cease! +#include +#include +#endif //----------------------------------------------------------------------------// // // @@ -87,7 +76,7 @@ namespace boost { #endif { - BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); + BOOST_STATIC_ASSERT_MSG(sizeof(T) > 0, "The template arguments to common_type must be complete types"); public: typedef T type; }; @@ -99,16 +88,18 @@ namespace type_traits_detail { struct common_type_2 { private: - BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); - BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U)); - static bool declval_bool(); // workaround gcc bug; not required by std - static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std - static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std - static typename add_rvalue_reference::type declval_b(); + BOOST_STATIC_ASSERT_MSG(sizeof(T) > 0, "The template arguments to common_type must be complete types"); + BOOST_STATIC_ASSERT_MSG(sizeof(U) > 0, "The template arguments to common_type must be complete types"); #if !defined(BOOST_NO_CXX11_DECLTYPE) public: typedef decltype(declval() ? declval() : declval()) type; +#elif defined(BOOST_COMMON_TYPE_USE_TYPEOF) + static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_b(); + public: + typedef __typeof__(declval_b() ? declval_T() : declval_U()) type; #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) public: typedef typename detail_type_traits_common_type::common_type_impl< @@ -116,6 +107,9 @@ namespace type_traits_detail { typename remove_cv::type >::type type; #else + static typename add_rvalue_reference::type declval_T(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_U(); // workaround gcc bug; not required by std + static typename add_rvalue_reference::type declval_b(); public: typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type; #endif