1
dnl Copyright 2002, The libsigc++ Development Team
3
dnl This library is free software; you can redistribute it and/or
4
dnl modify it under the terms of the GNU Lesser General Public
5
dnl License as published by the Free Software Foundation; either
6
dnl version 2.1 of the License, or (at your option) any later version.
8
dnl This library is distributed in the hope that it will be useful,
9
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
10
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
dnl Lesser General Public License for more details.
13
dnl You should have received a copy of the GNU Lesser General Public
14
dnl License along with this library; if not, write to the Free Software
15
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
include(template.macros.m4)
21
dnl How to call the darn thing!
22
define([LAMBDA_GROUP_FACTORY],[dnl
23
template <class T_functor, LOOP(class T_type%1, $1)>
24
lambda<lambda_group$1<T_functor, LOOP(typename unwrap_reference<T_type%1>::type, $1)> >
25
group(const T_functor& _A_func, LOOP(T_type%1 _A_%1, $1))
27
typedef lambda_group$1<T_functor, LOOP(typename unwrap_reference<T_type%1>::type, $1)> T_lambda;
28
return lambda<T_lambda>(T_lambda(_A_func, LOOP(_A_%1, $1)));
33
dnl How to call the darn thing!
34
define([LAMBDA_GROUP_DO],[dnl
35
define([_L_],[LOOP(_A_%1, $2)])dnl
36
define([_T_],[LOOP(T_arg%1, $2)])dnl
37
dnl Please someone get a gun!
38
template <LOOP(class T_arg%1, $2)>
39
typename deduce_result_type<LOOP(T_arg%1,$2)>::type
40
operator() (LOOP(T_arg%1 _A_%1, $2)) const
41
{ return this->func_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
42
typename value%1_type::template deduce_result_type<LOOP(T_arg%1,$2)>::type],$1)>(LOOP([
43
this->value%1_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
44
_P_(T_arg%1)],$2)>(_L_)],$1)); }
46
#ifndef SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
47
template <LOOP(class T_arg%1, $2)>
48
typename deduce_result_type<LOOP(T_arg%1,$2)>::type
49
sun_forte_workaround (LOOP(T_arg%1 _A_%1, $2)) const
50
{ return this->func_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
51
typename value%1_type::template deduce_result_type<LOOP(T_arg%1,$2)>::type],$1)>(LOOP([
52
this->value%1_.SIGC_WORKAROUND_OPERATOR_PARENTHESES<LOOP([
53
_P_(T_arg%1)],$2)>(_L_)],$1)); }
54
#endif //SIGC_TEMPLATE_SPECIALIZATION_OPERATOR_OVERLOAD
58
dnl This really doesn't have much to do with lambda other than
59
dnl holding lambdas with in itself.
60
define([LAMBDA_GROUP],[dnl
61
template <class T_functor, LOOP(class T_type%1, $1)>
62
struct lambda_group$1 : public lambda_base
64
typedef typename functor_trait<T_functor>::result_type result_type;dnl
66
typedef typename lambda<T_type%1>::lambda_type value%1_type;])
67
typedef typename adaptor_trait<T_functor>::adaptor_type functor_type;
69
template <LOOP(class T_arg%1=void,$2)>
70
struct deduce_result_type
71
{ typedef typename functor_type::template deduce_result_type<LOOP([
72
typename value%1_type::template deduce_result_type<LOOP([
73
_P_(T_arg%1)],$2)>::type],$1)
79
FOR(1,CALL_SIZE,[[LAMBDA_GROUP_DO($1,%1)]])dnl
80
lambda_group$1(typename type_trait<T_functor>::take _A_func, LOOP(typename type_trait<T_type%1>::take _A_%1, $1))
81
: LOOP(value%1_(_A_%1), $1), func_(_A_func) {}dnl
84
value%1_type value%1_;])
85
mutable functor_type func_;
88
template <class T_functor, LOOP(class T_type%1, $1)>
89
typename lambda_group$1<T_functor, LOOP(T_type%1, $1)>::result_type
90
lambda_group$1<T_functor, LOOP(T_type%1, $1)>::operator ()() const
91
{ return func_(LOOP(value%1_(), $1)); }
94
//template specialization of visit_each<>(action, functor):
95
template <class T_action, class T_functor, LOOP(class T_type%1, $1)>
96
void visit_each(const T_action& _A_action,
97
const lambda_group$1<T_functor, LOOP(T_type%1, $1)>& _A_target)
100
visit_each(_A_action, _A_target.value%1_);])
101
visit_each(_A_action, _A_target.func_);
108
#include <sigc++/adaptors/lambda/base.h>
110
/** @defgroup group_ group()
111
* sigc::group() alters an arbitrary functor by rebuilding its arguments from one or more lambda expressions.
112
* For each parameter that should be passed to the wrapped functor one lambda expression
113
* has to be passed into group(). Lambda selectors can be used as placeholders for the
114
* arguments passed into the new functor. Arguments that don't have a placeholder in one
115
* of the lambda expressions are dropped.
119
* void foo(int, int);
121
* // argument binding ...
122
* sigc::group(&foo,10,sigc::_1)(20); //fixes the first argument and calls foo(10,20)
123
* sigc::group(&foo,sigc::_1,30)(40); //fixes the second argument and calls foo(40,30)
124
* // argument reordering ...
125
* sigc::group(&foo,sigc::_2,sigc::_1)(1,2); //calls foo(2,1)
126
* // argument hiding ...
127
* sigc::group(&foo,sigc::_1,sigc::_2)(1,2,3); //calls foo(1,2)
128
* // functor composition ...
129
* sigc::group(&foo,sigc::_1,sigc::group(&bar,sigc::_2))(1,2); //calls foo(1,bar(2))
130
* // algebraic expressions ...
131
* sigc::group(&foo,sigc::_1*sigc::_2,sigc::_1/sigc::_2)(6,3); //calls foo(6*3,6/3)
134
* The functor sigc::group() returns can be passed into
135
* sigc::signal::connect() directly.
139
* sigc::signal<void,int,int> some_signal;
141
* some_signal.connect(sigc::group(&foo,sigc::_2));
144
* Like in sigc::bind() you can bind references to functors by passing the objects
145
* through the sigc::ref() helper function.
150
* sigc::signal<void> some_signal;
152
* some_signal.connect(sigc::group(&foo,sigc::ref(some_int)));
155
* If you bind an object of a sigc::trackable derived type to a functor
156
* by reference, a slot assigned to the group adaptor is cleared automatically
157
* when the object goes out of scope.
161
* struct bar : public sigc::trackable {} some_bar;
162
* sigc::signal<void> some_signal;
164
* some_signal.connect(sigc::group(&foo,sigc::ref(some_bar)));
165
* // disconnected automatically if some_bar goes out of scope
168
* @ingroup adaptors, lambdas
173
FOR(1,3,[[LAMBDA_GROUP(%1, CALL_SIZE)]])
174
FOR(1,3,[[LAMBDA_GROUP_FACTORY(%1)]])
176
} /* namespace sigc */