// common_type.hpp ---------------------------------------------------------// // Copyright 2008 Howard Hinnant // Copyright 2008 Beman Dawes // Distributed under the Boost Software License, Version 1.0. // See http://www.boost.org/LICENSE_1_0.txt #ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP #define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP #include #ifdef __SUNPRO_CC # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF #endif #ifdef __IBMCPP__ # define BOOST_COMMON_TYPE_DONT_USE_TYPEOF #endif //----------------------------------------------------------------------------// #if defined(BOOST_NO_VARIADIC_TEMPLATES) #define BOOST_COMMON_TYPE_ARITY 3 #endif //----------------------------------------------------------------------------// #if defined(BOOST_NO_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) #define BOOST_TYPEOF_SILENT #include // boost wonders never cease! #endif //----------------------------------------------------------------------------// #ifndef BOOST_NO_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_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_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) #include #include #endif #include #include #include //----------------------------------------------------------------------------// // // // C++03 implementation of // // 20.6.7 Other transformations [meta.trans.other] // // Written by Howard Hinnant // // Adapted for Boost by Beman Dawes, Vicente Botet and Jeffrey Hellrung // // // //----------------------------------------------------------------------------// namespace boost { // prototype #if !defined(BOOST_NO_VARIADIC_TEMPLATES) template struct common_type; #else // or no specialization template struct common_type { public: typedef typename common_type::type, V>::type type; }; #endif // 1 arg template #if !defined(BOOST_NO_VARIADIC_TEMPLATES) struct common_type #else struct common_type #endif { BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T)); public: typedef T type; }; // 2 args namespace type_traits_detail { template 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(); #if !defined(BOOST_NO_DECLTYPE) public: typedef decltype(declval() ? declval() : declval()) type; #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) public: typedef typename detail_type_traits_common_type::common_type_impl< typename remove_cv::type, typename remove_cv::type >::type type; #else public: typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type; #endif #if defined(__GNUC__) && __GNUC__ == 3 && (__GNUC_MINOR__ == 2 || __GNUC_MINOR__ == 3) public: void public_dummy_function_just_to_silence_warning(); #endif }; template struct common_type_2 { typedef T type; }; } #if !defined(BOOST_NO_VARIADIC_TEMPLATES) template struct common_type #else template struct common_type #endif : type_traits_detail::common_type_2 { }; // 3 or more args #if !defined(BOOST_NO_VARIADIC_TEMPLATES) template struct common_type { public: typedef typename common_type::type, V...>::type type; }; #endif } // namespace boost #endif // BOOST_TYPE_TRAITS_COMMON_TYPE_HPP