Re: [boost] new utility: function parameter caster

AMDG "Peter Dimov" wrote:
ali f wrote:
Hi again,
ok, here's my actual real world situation:
win->on_mouse_move.connect( args_cast<2, bool(int,int,bool,int)>( ( lambda::var(x) = lambda::_1, lambda::var(y) = lambda::_2, true ) ) );
The following: win->on_mouse_move.connect( ( lambda::var(x) = lambda::_1, lambda::var(y) = lambda::_2, lambda::_4, true ) ); would be Lambda's way to make it accept four arguments and only use the first two; it doesn't subscribe to boost::bind's philosophy of automatically ignoring extra arguments. Unfortunately, Lambda doesn't have _4, which makes the suggested workaround a bit limited. :-) Your attempt at using boost::bind with it didn't work probably because you didn't specify a return type. Try boost::bind<bool>.
Even that isn't enough. You need: win->on_mouse_move.connect( boost::bind<bool>( unlambda(( lambda::var(x) = lambda::_1, lambda::var(y) = lambda::_2, true )), _1, _2 ) ); This compiles fine. In Christ, Steven Watanabe

Steven Watanabe wrote:
Even that isn't enough. You need: win->on_mouse_move.connect( boost::bind<bool>( unlambda((
'unlambda' would be necessary with boost::lambda::bind, but it isn't needed for boost::bind. The following works for me. #include <boost/lambda/lambda.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream> int main() { int x = 0, y = 0; boost::function< bool( int, int, bool, int ) > on_mouse_move; namespace l = boost::lambda; on_mouse_move = boost::bind<bool>( (l::var(x) = l::_1, l::var(y) = l::_2, true), _1, _2 ); on_mouse_move( 1, 2, true, 4 ); std::cout << x << ' ' << y << std::endl; }

I had already tried it with the explicit return type. Doesnt work with that either. Steven Watanabe hit the spot though, the addition of unlambda did it. I suppose it's how boost.signals handles the function calls... thanks guys - ali ----- Original Message ----- From: "Peter Dimov" <pdimov@mmltd.net> Newsgroups: gmane.comp.lib.boost.devel Sent: Sunday, December 10, 2006 6:24 AM Subject: Re: new utility: function parameter caster
Steven Watanabe wrote:
Even that isn't enough. You need: win->on_mouse_move.connect( boost::bind<bool>( unlambda((
'unlambda' would be necessary with boost::lambda::bind, but it isn't needed for boost::bind. The following works for me.
#include <boost/lambda/lambda.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> #include <iostream>
int main() { int x = 0, y = 0;
boost::function< bool( int, int, bool, int ) > on_mouse_move;
namespace l = boost::lambda;
on_mouse_move = boost::bind<bool>( (l::var(x) = l::_1, l::var(y) = l::_2, true), _1, _2 );
on_mouse_move( 1, 2, true, 4 );
std::cout << x << ' ' << y << std::endl; }
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
ali f
-
Peter Dimov
-
Steven Watanabe