result_of.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Boost result_of library
  2. // Copyright Douglas Gregor 2004. Use, modification and
  3. // distribution is subject to the Boost Software License, Version
  4. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. // For more information, see http://www.boost.org/libs/utility
  7. #ifndef BOOST_RESULT_OF_HPP
  8. #define BOOST_RESULT_OF_HPP
  9. #include <boost/config.hpp>
  10. #include <boost/type_traits/ice.hpp>
  11. #include <boost/type.hpp>
  12. #include <boost/preprocessor.hpp>
  13. #include <boost/detail/workaround.hpp>
  14. #include <boost/mpl/has_xxx.hpp>
  15. #include <boost/mpl/if.hpp>
  16. #include <boost/mpl/bool.hpp>
  17. #ifndef BOOST_RESULT_OF_NUM_ARGS
  18. # define BOOST_RESULT_OF_NUM_ARGS 10
  19. #endif
  20. namespace boost {
  21. template<typename F> struct result_of;
  22. #if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  23. namespace detail {
  24. BOOST_MPL_HAS_XXX_TRAIT_DEF(result_type)
  25. template<typename F, typename FArgs, bool HasResultType> struct result_of_impl;
  26. template<typename F>
  27. struct result_of_void_impl
  28. {
  29. typedef void type;
  30. };
  31. template<typename R>
  32. struct result_of_void_impl<R (*)(void)>
  33. {
  34. typedef R type;
  35. };
  36. template<typename R>
  37. struct result_of_void_impl<R (&)(void)>
  38. {
  39. typedef R type;
  40. };
  41. template<typename F, typename FArgs>
  42. struct result_of_impl<F, FArgs, true>
  43. {
  44. typedef typename F::result_type type;
  45. };
  46. template<typename FArgs>
  47. struct is_function_with_no_args : mpl::false_ {};
  48. template<typename F>
  49. struct is_function_with_no_args<F(void)> : mpl::true_ {};
  50. template<typename F, typename FArgs>
  51. struct result_of_nested_result : F::template result<FArgs>
  52. {};
  53. template<typename F, typename FArgs>
  54. struct result_of_impl<F, FArgs, false>
  55. : mpl::if_<is_function_with_no_args<FArgs>,
  56. result_of_void_impl<F>,
  57. result_of_nested_result<F, FArgs> >::type
  58. {};
  59. } // end namespace detail
  60. #define BOOST_PP_ITERATION_PARAMS_1 (3,(0,BOOST_RESULT_OF_NUM_ARGS,<boost/utility/detail/result_of_iterate.hpp>))
  61. #include BOOST_PP_ITERATE()
  62. #else
  63. # define BOOST_NO_RESULT_OF 1
  64. #endif
  65. }
  66. #endif // BOOST_RESULT_OF_HPP