On Mon, Aug 11, 2003 at 10:54:40PM -0500, Aleksey Gurtovoy wrote:
> Gary Powell wrote:
> > >Consider the following snippet:
> > >
> > >    void show_warning( message_dialog const&, user_message );
> > >    void post_command( boost::function<void()> );
> > >
> > >    int main()
> > >    {
> > >        boost::function<void( user_message )> f( 
> > >              bind( &post_command
> > >                , ????( bind( &show_warning, message_dialog(), _1 ) )
> > >    //            ^^^^ what goes here?
> > >                )
> > >            );
> > >    }
> > >
> > >Could we make it work, somehow? Offers of a hand-written function 
> > >performing the composition are not accepted :)
> > >
> > 
> > I'm a bit confused by your request,
> >  Do you want both fns to be called? 
> 
> Nope. Please see http://article.gmane.org/gmane.comp.lib.boost.devel/23466
> for the semantics clarification. Basically, I want the whole bind 
> expression to return an unary function object which, when invoked, will
> use the argument to construct a nested nullary function object:
> 
>     bind( &show_warning, message_dialog(), <arg> )
> 
> and pass it as an argument to 'post_command'.
> 
> Does it make more sense now?

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".)

-- 
-Brian McNamara ([EMAIL PROTECTED])
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to