Chris@16: // Boost result_of library Chris@16: Chris@16: // Copyright Douglas Gregor 2004. Use, modification and Chris@16: // distribution is subject to the Boost Software License, Version Chris@16: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: // For more information, see http://www.boost.org/libs/utility Chris@16: #ifndef BOOST_RESULT_OF_HPP Chris@16: #define BOOST_RESULT_OF_HPP Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifndef BOOST_RESULT_OF_NUM_ARGS Chris@16: # define BOOST_RESULT_OF_NUM_ARGS 16 Chris@16: #endif Chris@16: Chris@16: // Use the decltype-based version of result_of by default if the compiler Chris@16: // supports N3276 . Chris@16: // The user can force the choice by defining BOOST_RESULT_OF_USE_DECLTYPE, Chris@16: // BOOST_RESULT_OF_USE_TR1, or BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK but not more than one! Chris@16: #if (defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1)) || \ Chris@16: (defined(BOOST_RESULT_OF_USE_DECLTYPE) && defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)) || \ Chris@16: (defined(BOOST_RESULT_OF_USE_TR1) && defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK)) Chris@16: # error More than one of BOOST_RESULT_OF_USE_DECLTYPE, BOOST_RESULT_OF_USE_TR1 and \ Chris@16: BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK cannot be defined at the same time. Chris@16: #endif Chris@16: Chris@16: #if defined(BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK) && defined(BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE) Chris@16: # error Cannot fallback to decltype if BOOST_MPL_CFG_NO_HAS_XXX_TEMPLATE is not defined. Chris@16: #endif Chris@16: Chris@16: #ifndef BOOST_RESULT_OF_USE_TR1 Chris@16: # ifndef BOOST_RESULT_OF_USE_DECLTYPE Chris@16: # ifndef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK Chris@16: # ifndef BOOST_NO_CXX11_DECLTYPE_N3276 // this implies !defined(BOOST_NO_CXX11_DECLTYPE) Chris@16: # define BOOST_RESULT_OF_USE_DECLTYPE Chris@16: # else Chris@16: # define BOOST_RESULT_OF_USE_TR1 Chris@16: # endif Chris@16: # endif Chris@16: # endif Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: template struct result_of; Chris@16: template struct tr1_result_of; // a TR1-style implementation of result_of Chris@16: Chris@101: #if !defined(BOOST_NO_SFINAE) Chris@16: namespace detail { Chris@16: Chris@16: BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type) Chris@16: Chris@101: // Work around a nvcc bug by only defining has_result when it's needed. Chris@101: #ifdef BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK Chris@16: BOOST_MPL_HAS_XXX_TEMPLATE_DEF(result) Chris@101: #endif Chris@16: Chris@16: template struct tr1_result_of_impl; Chris@16: Chris@16: template struct cpp0x_result_of; Chris@16: Chris@16: #ifdef BOOST_NO_SFINAE_EXPR Chris@16: Chris@16: // There doesn't seem to be any other way to turn this off such that the presence of Chris@16: // the user-defined operator,() below doesn't cause spurious warning all over the place, Chris@16: // so unconditionally turn it off. Chris@16: #if BOOST_MSVC Chris@16: # pragma warning(disable: 4913) // user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used Chris@16: #endif Chris@16: Chris@16: struct result_of_private_type {}; Chris@16: Chris@16: struct result_of_weird_type { Chris@16: friend result_of_private_type operator,(result_of_private_type, result_of_weird_type); Chris@16: }; Chris@16: Chris@16: typedef char result_of_yes_type; // sizeof(result_of_yes_type) == 1 Chris@16: typedef char (&result_of_no_type)[2]; // sizeof(result_of_no_type) == 2 Chris@16: Chris@16: template Chris@16: result_of_no_type result_of_is_private_type(T const &); Chris@16: result_of_yes_type result_of_is_private_type(result_of_private_type); Chris@16: Chris@16: template Chris@16: struct result_of_callable_class : C { Chris@16: result_of_callable_class(); Chris@16: typedef result_of_private_type const &(*pfn_t)(...); Chris@16: operator pfn_t() const volatile; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_wrap_callable_class { Chris@16: typedef result_of_callable_class type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_wrap_callable_class { Chris@16: typedef result_of_callable_class const type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_wrap_callable_class { Chris@16: typedef result_of_callable_class volatile type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_wrap_callable_class { Chris@16: typedef result_of_callable_class const volatile type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_wrap_callable_class { Chris@16: typedef typename result_of_wrap_callable_class::type &type; Chris@16: }; Chris@16: Chris@16: template struct cpp0x_result_of_impl; Chris@16: Chris@16: #else // BOOST_NO_SFINAE_EXPR Chris@16: Chris@16: template Chris@16: struct result_of_always_void Chris@16: { Chris@16: typedef void type; Chris@16: }; Chris@16: Chris@16: template struct cpp0x_result_of_impl {}; Chris@16: Chris@16: #endif // BOOST_NO_SFINAE_EXPR Chris@16: Chris@16: template Chris@16: struct result_of_void_impl Chris@16: { Chris@16: typedef void type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_void_impl Chris@16: { Chris@16: typedef R type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct result_of_void_impl Chris@16: { Chris@16: typedef R type; Chris@16: }; Chris@16: Chris@16: // Determine the return type of a function pointer or pointer to member. Chris@16: template Chris@16: struct result_of_pointer Chris@16: : tr1_result_of_impl::type, FArgs, false> { }; Chris@16: Chris@16: template Chris@16: struct tr1_result_of_impl Chris@16: { Chris@16: typedef typename F::result_type type; Chris@16: }; Chris@16: Chris@16: template Chris@16: struct is_function_with_no_args : mpl::false_ {}; Chris@16: Chris@16: template Chris@16: struct is_function_with_no_args : mpl::true_ {}; Chris@16: Chris@16: template Chris@16: struct result_of_nested_result : F::template result Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct tr1_result_of_impl Chris@16: : mpl::if_, Chris@16: result_of_void_impl, Chris@16: result_of_nested_result >::type Chris@16: {}; Chris@16: Chris@16: } // end namespace detail Chris@16: Chris@16: #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,)) Chris@16: #include BOOST_PP_ITERATE() Chris@16: Chris@16: #else Chris@16: # define BOOST_NO_RESULT_OF 1 Chris@16: #endif Chris@16: Chris@16: } Chris@16: Chris@16: #endif // BOOST_RESULT_OF_HPP