result.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #if !defined(BOOST_PP_IS_ITERATING)
  2. // Copyright David Abrahams 2002.
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. # ifndef RESULT_DWA2002521_HPP
  7. # define RESULT_DWA2002521_HPP
  8. # include <boost/type.hpp>
  9. # include <boost/python/detail/preprocessor.hpp>
  10. # include <boost/python/detail/type_traits.hpp>
  11. # include <boost/mpl/if.hpp>
  12. # include <boost/preprocessor/comma_if.hpp>
  13. # include <boost/preprocessor/iterate.hpp>
  14. # include <boost/preprocessor/debug/line.hpp>
  15. # include <boost/preprocessor/enum_params.hpp>
  16. # include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  17. namespace boost { namespace python { namespace detail {
  18. // Defines a family of overloaded function which, given x, a function
  19. // pointer, member [function] pointer, or an AdaptableFunction object,
  20. // returns a pointer to type<R>*, where R is the result type of
  21. // invoking the result of bind(x).
  22. //
  23. // In order to work around bugs in deficient compilers, if x might be
  24. // an AdaptableFunction object, you must pass OL as a second argument
  25. // to get this to work portably.
  26. # define BOOST_PP_ITERATION_PARAMS_1 \
  27. (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/result.hpp>, BOOST_PYTHON_FUNCTION_POINTER))
  28. # include BOOST_PP_ITERATE()
  29. # define BOOST_PP_ITERATION_PARAMS_1 \
  30. (4, (0, BOOST_PYTHON_CV_COUNT - 1, <boost/python/detail/result.hpp>, BOOST_PYTHON_POINTER_TO_MEMBER))
  31. # include BOOST_PP_ITERATE()
  32. template <class R, class T>
  33. boost::type<R>* result(R (T::*), int = 0) { return 0; }
  34. # if (defined(__MWERKS__) && __MWERKS__ < 0x3000)
  35. // This code actually works on all implementations, but why use it when we don't have to?
  36. template <class T>
  37. struct get_result_type
  38. {
  39. typedef boost::type<typename T::result_type> type;
  40. };
  41. struct void_type
  42. {
  43. typedef void type;
  44. };
  45. template <class T>
  46. struct result_result
  47. {
  48. typedef typename mpl::if_c<
  49. is_class<T>::value
  50. , get_result_type<T>
  51. , void_type
  52. >::type t1;
  53. typedef typename t1::type* type;
  54. };
  55. template <class X>
  56. typename result_result<X>::type
  57. result(X const&, short) { return 0; }
  58. # else // Simpler code for more-capable compilers
  59. template <class X>
  60. boost::type<typename X::result_type>*
  61. result(X const&, short = 0) { return 0; }
  62. # endif
  63. }}} // namespace boost::python::detail
  64. # endif // RESULT_DWA2002521_HPP
  65. /* --------------- function pointers --------------- */
  66. // For gcc 4.4 compatability, we must include the
  67. // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
  68. #else // BOOST_PP_IS_ITERATING
  69. #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_FUNCTION_POINTER
  70. # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
  71. && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
  72. # line BOOST_PP_LINE(__LINE__, result.hpp(function pointers))
  73. # endif
  74. # define N BOOST_PP_ITERATION()
  75. template <class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
  76. boost::type<R>* result(R (*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)), int = 0)
  77. {
  78. return 0;
  79. }
  80. # undef N
  81. /* --------------- pointers-to-members --------------- */
  82. #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == BOOST_PYTHON_POINTER_TO_MEMBER
  83. // Outer over cv-qualifiers
  84. # define BOOST_PP_ITERATION_PARAMS_2 (3, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/detail/result.hpp>))
  85. # include BOOST_PP_ITERATE()
  86. #elif BOOST_PP_ITERATION_DEPTH() == 2
  87. # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
  88. && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
  89. # line BOOST_PP_LINE(__LINE__, result.hpp(pointers-to-members))
  90. # endif
  91. // Inner over arities
  92. # define N BOOST_PP_ITERATION()
  93. # define Q BOOST_PYTHON_CV_QUALIFIER(BOOST_PP_RELATIVE_ITERATION(1))
  94. template <class R, class T BOOST_PP_ENUM_TRAILING_PARAMS_Z(1, N, class A)>
  95. boost::type<R>* result(R (T::*)(BOOST_PP_ENUM_PARAMS_Z(1, N, A)) Q, int = 0)
  96. {
  97. return 0;
  98. }
  99. # undef N
  100. # undef Q
  101. #endif // BOOST_PP_ITERATION_DEPTH()
  102. #endif