function_ptr.hpp 4.0 KB

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