function_ptr.hpp 4.1 KB

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