member_function_ptr.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !BOOST_PHOENIX_IS_ITERATING
  7. #include <boost/phoenix/core/limits.hpp>
  8. #include <boost/phoenix/support/iterate.hpp>
  9. namespace boost { namespace phoenix { namespace detail
  10. {
  11. template <int N>
  12. struct member_function_ptr_impl
  13. {
  14. template <typename RT, typename FP>
  15. struct impl;
  16. };
  17. template <int N, typename RT, typename FP>
  18. struct member_function_ptr
  19. : member_function_ptr_impl<N>::template impl<RT, FP>
  20. {
  21. typedef typename member_function_ptr_impl<N>::
  22. template impl<RT, FP> base;
  23. member_function_ptr(FP fp_)
  24. : base(fp_) {}
  25. using base::fp;
  26. bool operator==(member_function_ptr const & rhs) const
  27. {
  28. return fp == rhs.fp;
  29. }
  30. template <int M, typename RhsRT, typename RhsFP>
  31. bool operator==(member_function_ptr<M, RhsRT, RhsFP> const &) const
  32. {
  33. return false;
  34. }
  35. };
  36. template <>
  37. struct member_function_ptr_impl<0>
  38. {
  39. template <typename RT, typename FP>
  40. struct impl
  41. {
  42. typedef RT result_type;
  43. impl(FP fp_)
  44. : fp(fp_) {}
  45. template <typename Class>
  46. RT operator()(Class& obj) const
  47. {
  48. BOOST_PROTO_USE_GET_POINTER();
  49. typedef typename proto::detail::class_member_traits<FP>::class_type class_type;
  50. return (BOOST_PROTO_GET_POINTER(class_type, obj) ->*fp)();
  51. }
  52. template <typename Class>
  53. RT operator()(Class* obj) const
  54. {
  55. return (obj->*fp)();
  56. }
  57. FP fp;
  58. };
  59. };
  60. #if !defined(BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES)
  61. #include <boost/phoenix/bind/detail/cpp03/preprocessed/member_function_ptr.hpp>
  62. #else
  63. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  64. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/member_function_ptr_" BOOST_PHOENIX_LIMIT_STR ".hpp")
  65. #endif
  66. /*=============================================================================
  67. Copyright (c) 2001-2007 Joel de Guzman
  68. Distributed under the Boost Software License, Version 1.0. (See accompanying
  69. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  70. ==============================================================================*/
  71. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  72. #pragma wave option(preserve: 1)
  73. #endif
  74. #define BOOST_PHOENIX_ITERATION_PARAMS \
  75. (3, (1, BOOST_PHOENIX_COMPOSITE_LIMIT, \
  76. <boost/phoenix/bind/detail/cpp03/member_function_ptr.hpp>))
  77. #include BOOST_PHOENIX_ITERATE()
  78. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  79. #pragma wave option(output: null)
  80. #endif
  81. #endif
  82. }}} // namespace boost::phoenix::detail
  83. ///////////////////////////////////////////////////////////////////////////////
  84. //
  85. // Preprocessor vertical repetition code
  86. //
  87. ///////////////////////////////////////////////////////////////////////////////
  88. #else
  89. template <>
  90. struct member_function_ptr_impl<BOOST_PHOENIX_ITERATION>
  91. {
  92. template <typename RT, typename FP>
  93. struct impl
  94. {
  95. typedef RT result_type;
  96. impl(FP fp_)
  97. : fp(fp_) {}
  98. template <typename Class, BOOST_PHOENIX_typename_A>
  99. RT operator()(Class& obj, BOOST_PHOENIX_A_ref_a) const
  100. {
  101. BOOST_PROTO_USE_GET_POINTER();
  102. typedef typename proto::detail::class_member_traits<FP>::class_type class_type;
  103. return (BOOST_PROTO_GET_POINTER(class_type, obj)->*fp)(BOOST_PHOENIX_a);
  104. }
  105. template <typename Class, BOOST_PHOENIX_typename_A>
  106. RT operator()(Class* obj, BOOST_PHOENIX_A_ref_a) const
  107. {
  108. return (obj->*fp)(BOOST_PHOENIX_a);
  109. }
  110. FP fp;
  111. };
  112. };
  113. #endif // defined(BOOST_PP_IS_ITERATING)