actions.hpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // -- Boost Lambda Library - actions.hpp ----------------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see www.boost.org
  8. // ----------------------------------------------------------------
  9. #ifndef BOOST_LAMBDA_ACTIONS_HPP
  10. #define BOOST_LAMBDA_ACTIONS_HPP
  11. namespace boost {
  12. namespace lambda {
  13. template<int Arity, class Act> class action;
  14. // these need to be defined here, since the corresponding lambda
  15. // functions are members of lambda_functor classes
  16. class assignment_action {};
  17. class subscript_action {};
  18. template <class Action> class other_action;
  19. // action for specifying the explicit return type
  20. template <class RET> class explicit_return_type_action {};
  21. // action for preventing the expansion of a lambda expression
  22. struct protect_action {};
  23. // must be defined here, comma is a special case
  24. struct comma_action {};
  25. // actions, for which the existence of protect is checked in return type
  26. // deduction.
  27. template <class Action> struct is_protectable {
  28. BOOST_STATIC_CONSTANT(bool, value = false);
  29. };
  30. // NOTE: comma action is protectable. Other protectable actions
  31. // are listed in operator_actions.hpp
  32. template<> struct is_protectable<other_action<comma_action> > {
  33. BOOST_STATIC_CONSTANT(bool, value = true);
  34. };
  35. namespace detail {
  36. // this type is used in return type deductions to signal that deduction
  37. // did not find a result. It does not necessarily mean an error, it commonly
  38. // means that something else should be tried.
  39. class unspecified {};
  40. }
  41. // function action is a special case: bind functions can be called with
  42. // the return type specialized explicitly e.g. bind<int>(foo);
  43. // If this call syntax is used, the return type is stored in the latter
  44. // argument of function_action template. Otherwise the argument gets the type
  45. // 'unspecified'.
  46. // This argument is only relevant in the return type deduction code
  47. template <int I, class Result_type = detail::unspecified>
  48. class function_action {};
  49. template<class T> class function_action<1, T> {
  50. public:
  51. template<class RET, class A1>
  52. static RET apply(A1& a1) {
  53. return function_adaptor<typename boost::remove_cv<A1>::type>::
  54. template apply<RET>(a1);
  55. }
  56. };
  57. template<class T> class function_action<2, T> {
  58. public:
  59. template<class RET, class A1, class A2>
  60. static RET apply(A1& a1, A2& a2) {
  61. return function_adaptor<typename boost::remove_cv<A1>::type>::
  62. template apply<RET>(a1, a2);
  63. }
  64. };
  65. template<class T> class function_action<3, T> {
  66. public:
  67. template<class RET, class A1, class A2, class A3>
  68. static RET apply(A1& a1, A2& a2, A3& a3) {
  69. return function_adaptor<typename boost::remove_cv<A1>::type>::
  70. template apply<RET>(a1, a2, a3);
  71. }
  72. };
  73. template<class T> class function_action<4, T> {
  74. public:
  75. template<class RET, class A1, class A2, class A3, class A4>
  76. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4) {
  77. return function_adaptor<typename boost::remove_cv<A1>::type>::
  78. template apply<RET>(a1, a2, a3, a4);
  79. }
  80. };
  81. template<class T> class function_action<5, T> {
  82. public:
  83. template<class RET, class A1, class A2, class A3, class A4, class A5>
  84. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5) {
  85. return function_adaptor<typename boost::remove_cv<A1>::type>::
  86. template apply<RET>(a1, a2, a3, a4, a5);
  87. }
  88. };
  89. template<class T> class function_action<6, T> {
  90. public:
  91. template<class RET, class A1, class A2, class A3, class A4, class A5,
  92. class A6>
  93. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6) {
  94. return function_adaptor<typename boost::remove_cv<A1>::type>::
  95. template apply<RET>(a1, a2, a3, a4, a5, a6);
  96. }
  97. };
  98. template<class T> class function_action<7, T> {
  99. public:
  100. template<class RET, class A1, class A2, class A3, class A4, class A5,
  101. class A6, class A7>
  102. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7) {
  103. return function_adaptor<typename boost::remove_cv<A1>::type>::
  104. template apply<RET>(a1, a2, a3, a4, a5, a6, a7);
  105. }
  106. };
  107. template<class T> class function_action<8, T> {
  108. public:
  109. template<class RET, class A1, class A2, class A3, class A4, class A5,
  110. class A6, class A7, class A8>
  111. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7,
  112. A8& a8) {
  113. return function_adaptor<typename boost::remove_cv<A1>::type>::
  114. template apply<RET>(a1, a2, a3, a4, a5, a6, a7, a8);
  115. }
  116. };
  117. template<class T> class function_action<9, T> {
  118. public:
  119. template<class RET, class A1, class A2, class A3, class A4, class A5,
  120. class A6, class A7, class A8, class A9>
  121. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7,
  122. A8& a8, A9& a9) {
  123. return function_adaptor<typename boost::remove_cv<A1>::type>::
  124. template apply<RET>(a1, a2, a3, a4, a5, a6, a7, a8, a9);
  125. }
  126. };
  127. template<class T> class function_action<10, T> {
  128. public:
  129. template<class RET, class A1, class A2, class A3, class A4, class A5,
  130. class A6, class A7, class A8, class A9, class A10>
  131. static RET apply(A1& a1, A2& a2, A3& a3, A4& a4, A5& a5, A6& a6, A7& a7,
  132. A8& a8, A9& a9, A10& a10) {
  133. return function_adaptor<typename boost::remove_cv<A1>::type>::
  134. template apply<RET>(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
  135. }
  136. };
  137. } // namespace lambda
  138. } // namespace boost
  139. #endif