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