1
// Boost Lambda Library - operator_lambda_func_base.hpp -----------------
3
// Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
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)
9
// For more information, see www.boost.org
11
// ------------------------------------------------------------
13
#ifndef BOOST_LAMBDA_OPERATOR_LAMBDA_FUNC_BASE_HPP
14
#define BOOST_LAMBDA_OPERATOR_LAMBDA_FUNC_BASE_HPP
20
// These operators cannot be implemented as apply functions of action
24
// Specialization for comma.
26
class lambda_functor_base<other_action<comma_action>, Args> {
30
explicit lambda_functor_base(const Args& a) : args(a) {}
32
template<class RET, CALL_TEMPLATE_ARGS>
33
RET call(CALL_FORMAL_ARGS) const {
34
return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS),
35
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
39
template<class SigArgs> struct sig {
42
detail::deduce_argument_types<Args, SigArgs>::type rets_t;
44
typedef typename return_type_2_comma< // comma needs special handling
45
typename detail::element_or_null<0, rets_t>::type,
46
typename detail::element_or_null<1, rets_t>::type
54
// helper traits to make the expression shorter, takes binary action
55
// bound argument tuple, open argument tuple and gives the return type
57
template<class Action, class Bound, class Open> class binary_rt {
60
detail::deduce_argument_types<Bound, Open>::type rets_t;
62
typedef typename return_type_2_prot<
64
typename detail::element_or_null<0, rets_t>::type,
65
typename detail::element_or_null<1, rets_t>::type
70
// same for unary actions
71
template<class Action, class Bound, class Open> class unary_rt {
74
detail::deduce_argument_types<Bound, Open>::type rets_t;
76
typedef typename return_type_1_prot<
78
typename detail::element_or_null<0, rets_t>::type
85
// Specialization for logical and (to preserve shortcircuiting)
86
// this could be done with a macro as the others, code used to be different
88
class lambda_functor_base<logical_action<and_action>, Args> {
92
explicit lambda_functor_base(const Args& a) : args(a) {}
94
template<class RET, CALL_TEMPLATE_ARGS>
95
RET call(CALL_FORMAL_ARGS) const {
96
return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) &&
97
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
99
template<class SigArgs> struct sig {
101
detail::binary_rt<logical_action<and_action>, Args, SigArgs>::type type;
105
// Specialization for logical or (to preserve shortcircuiting)
106
// this could be done with a macro as the others, code used to be different
108
class lambda_functor_base<logical_action< or_action>, Args> {
112
explicit lambda_functor_base(const Args& a) : args(a) {}
114
template<class RET, CALL_TEMPLATE_ARGS>
115
RET call(CALL_FORMAL_ARGS) const {
116
return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) ||
117
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS);
120
template<class SigArgs> struct sig {
122
detail::binary_rt<logical_action<or_action>, Args, SigArgs>::type type;
126
// Specialization for subscript
128
class lambda_functor_base<other_action<subscript_action>, Args> {
132
explicit lambda_functor_base(const Args& a) : args(a) {}
134
template<class RET, CALL_TEMPLATE_ARGS>
135
RET call(CALL_FORMAL_ARGS) const {
136
return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS)
137
[detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS)];
140
template<class SigArgs> struct sig {
142
detail::binary_rt<other_action<subscript_action>, Args, SigArgs>::type
148
#define BOOST_LAMBDA_BINARY_ACTION(SYMBOL, ACTION_CLASS) \
149
template<class Args> \
150
class lambda_functor_base<ACTION_CLASS, Args> { \
154
explicit lambda_functor_base(const Args& a) : args(a) {} \
156
template<class RET, CALL_TEMPLATE_ARGS> \
157
RET call(CALL_FORMAL_ARGS) const { \
158
return detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) \
160
detail::select(boost::tuples::get<1>(args), CALL_ACTUAL_ARGS); \
162
template<class SigArgs> struct sig { \
164
detail::binary_rt<ACTION_CLASS, Args, SigArgs>::type type; \
168
#define BOOST_LAMBDA_PREFIX_UNARY_ACTION(SYMBOL, ACTION_CLASS) \
169
template<class Args> \
170
class lambda_functor_base<ACTION_CLASS, Args> { \
174
explicit lambda_functor_base(const Args& a) : args(a) {} \
176
template<class RET, CALL_TEMPLATE_ARGS> \
177
RET call(CALL_FORMAL_ARGS) const { \
179
detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS); \
181
template<class SigArgs> struct sig { \
183
detail::unary_rt<ACTION_CLASS, Args, SigArgs>::type type; \
187
#define BOOST_LAMBDA_POSTFIX_UNARY_ACTION(SYMBOL, ACTION_CLASS) \
188
template<class Args> \
189
class lambda_functor_base<ACTION_CLASS, Args> { \
193
explicit lambda_functor_base(const Args& a) : args(a) {} \
195
template<class RET, CALL_TEMPLATE_ARGS> \
196
RET call(CALL_FORMAL_ARGS) const { \
198
detail::select(boost::tuples::get<0>(args), CALL_ACTUAL_ARGS) SYMBOL; \
200
template<class SigArgs> struct sig { \
202
detail::unary_rt<ACTION_CLASS, Args, SigArgs>::type type; \
206
BOOST_LAMBDA_BINARY_ACTION(+,arithmetic_action<plus_action>)
207
BOOST_LAMBDA_BINARY_ACTION(-,arithmetic_action<minus_action>)
208
BOOST_LAMBDA_BINARY_ACTION(*,arithmetic_action<multiply_action>)
209
BOOST_LAMBDA_BINARY_ACTION(/,arithmetic_action<divide_action>)
210
BOOST_LAMBDA_BINARY_ACTION(%,arithmetic_action<remainder_action>)
212
BOOST_LAMBDA_BINARY_ACTION(<<,bitwise_action<leftshift_action>)
213
BOOST_LAMBDA_BINARY_ACTION(>>,bitwise_action<rightshift_action>)
214
BOOST_LAMBDA_BINARY_ACTION(&,bitwise_action<and_action>)
215
BOOST_LAMBDA_BINARY_ACTION(|,bitwise_action<or_action>)
216
BOOST_LAMBDA_BINARY_ACTION(^,bitwise_action<xor_action>)
218
BOOST_LAMBDA_BINARY_ACTION(<,relational_action<less_action>)
219
BOOST_LAMBDA_BINARY_ACTION(>,relational_action<greater_action>)
220
BOOST_LAMBDA_BINARY_ACTION(<=,relational_action<lessorequal_action>)
221
BOOST_LAMBDA_BINARY_ACTION(>=,relational_action<greaterorequal_action>)
222
BOOST_LAMBDA_BINARY_ACTION(==,relational_action<equal_action>)
223
BOOST_LAMBDA_BINARY_ACTION(!=,relational_action<notequal_action>)
225
BOOST_LAMBDA_BINARY_ACTION(+=,arithmetic_assignment_action<plus_action>)
226
BOOST_LAMBDA_BINARY_ACTION(-=,arithmetic_assignment_action<minus_action>)
227
BOOST_LAMBDA_BINARY_ACTION(*=,arithmetic_assignment_action<multiply_action>)
228
BOOST_LAMBDA_BINARY_ACTION(/=,arithmetic_assignment_action<divide_action>)
229
BOOST_LAMBDA_BINARY_ACTION(%=,arithmetic_assignment_action<remainder_action>)
231
BOOST_LAMBDA_BINARY_ACTION(<<=,bitwise_assignment_action<leftshift_action>)
232
BOOST_LAMBDA_BINARY_ACTION(>>=,bitwise_assignment_action<rightshift_action>)
233
BOOST_LAMBDA_BINARY_ACTION(&=,bitwise_assignment_action<and_action>)
234
BOOST_LAMBDA_BINARY_ACTION(|=,bitwise_assignment_action<or_action>)
235
BOOST_LAMBDA_BINARY_ACTION(^=,bitwise_assignment_action<xor_action>)
237
BOOST_LAMBDA_BINARY_ACTION(=,other_action< assignment_action>)
240
BOOST_LAMBDA_PREFIX_UNARY_ACTION(+, unary_arithmetic_action<plus_action>)
241
BOOST_LAMBDA_PREFIX_UNARY_ACTION(-, unary_arithmetic_action<minus_action>)
242
BOOST_LAMBDA_PREFIX_UNARY_ACTION(~, bitwise_action<not_action>)
243
BOOST_LAMBDA_PREFIX_UNARY_ACTION(!, logical_action<not_action>)
244
BOOST_LAMBDA_PREFIX_UNARY_ACTION(++, pre_increment_decrement_action<increment_action>)
245
BOOST_LAMBDA_PREFIX_UNARY_ACTION(--, pre_increment_decrement_action<decrement_action>)
247
BOOST_LAMBDA_PREFIX_UNARY_ACTION(&,other_action<addressof_action>)
248
BOOST_LAMBDA_PREFIX_UNARY_ACTION(*,other_action<contentsof_action>)
250
BOOST_LAMBDA_POSTFIX_UNARY_ACTION(++, post_increment_decrement_action<increment_action>)
251
BOOST_LAMBDA_POSTFIX_UNARY_ACTION(--, post_increment_decrement_action<decrement_action>)
254
#undef BOOST_LAMBDA_POSTFIX_UNARY_ACTION
255
#undef BOOST_LAMBDA_PREFIX_UNARY_ACTION
256
#undef BOOST_LAMBDA_BINARY_ACTION
258
} // namespace lambda