Boost logo

Boost :

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


>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?

Ok, I really should have a cup of coffee before I answer these questions,

The problem with using "lambda" or "bind" in this case is one of order of operations. You want

// written as if I had inline function definitions.

void f(char *msg) {
  
     .....
     post_command(void) {
       ....
       show_warning(message_dialog(), msg);
     }
   }

now the problem is that you really can't do this elegantly in C++. You can pass the msg into show_warning either as a global or on the stack. Lambda makes the general assumption that you want to pass things on the stack. What you need is a temporary global.

I have some code that might do it, but its not released. (I'm also not sure that Brian's FC++ solution did it right either.) I could send you a copy and let you try if you want. Anyway it would look like this.

   boost::function<void( user_message )> f(
          ll::locals<user_message_type &>(_1) [
             bind( &post_command,
                bind(bind( &show_warning, message_dialog(),loc0 ) )
              ]
          );

This should cause a reference to the user_message to be able to be referenced inside of post_command.

But I haven't tested it and I don't have time this week either.

Anyway if there was a case for having a core language feature to do inline function definitions this is it.

     -Gary-

  -Gary-


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