Boost logo

Boost :

From: Powell, Gary (powellg_at_[hidden])
Date: 2003-08-12 11:20:53


Brian McNamara <lorgon_at_[hidden]> writes:

> I can't speak for bind/lambda, although I imagine there must be a way,
> probably involving delaying the evaluation of _1 for one step.
>
> Using FC++, it would be
>
> using fcpp::fun1;
> using fcpp::lambda;
> using fcpp::ptr_to_fun;
> fun1<user_message,void> f =
> lambda(X)[ ptr_to_fun(post_command)[
> lambda()[ ptr_to_fun(show_warning)[ message_dialog(), X ]
> ] ] ];
>
> The explicit lambda notation makes it easier to (mentally and
> syntactically) sort out functions like these where the placeholder
> variables are bound by a lambda (bind expression) other than the
> innermost one.
>
> (The calls to to ptr_to_fun above are necessary only to promote the
> function pointers into FC++ "functoids".)

Yep, the lambda(X) is nice because it shows where the argument is going to be used.

However Peter Dimov's original post was correct, bind/lambda "protect" or lambda's "unlambda", would do the same. The issue being keeping _1 from being evaluated until later.

  -Gary-


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk