[bind] deduce arguments types

Hi all,
I have written a small grammar for command line parsing where function
binders could be added as actors (callback) of a distinct option. The
simple example below shows that the free function id(...) is called if
the option -i is getting parsed and the bound member function is
called when -j is given:
bool id(int i)
{
return true; /* if id satisfies some preconditions, the parser will
evaluate the result value */
}
struct Id
{
void id(int i)
{
// the parser will not evaluate the 'void' result value
}
};
Id ident;
bool rc = cmdline::Parser

On Thursday, September 01, 2011 12:15:12 AM Martin Häfner wrote:
Hi all, <snip> The problem now is that I want to deduce the result type of the given actor as well as the argument type. Retrieving the result type is manageable with boost binders but I have no idea how I could retrieve the argument type in order to do a proper conversion from char* to int without the usage of make_adaptable<> which breaks the elegance of the binder usage at this point.
My self-written binder class exposes appropriate typedefs so the writer of the parser grammar does not have to cope with all that 'magic' template stuff, but I cannot get a working solution for boost::bind nor do I get a working solution with tr1 binders.
Maybe anybody could help or at least could explain me why the boost classes do not define these simple typedefs?
You lost me. The type of the arguments isn't known until the bound function is called. That is, for example, if you have a placeholder inside your bind expression, what would that type be? And this is one of the easier usecases ... It gets more complicated once you have nested calls to bind, or use some operators. You might want to look into Phoenix. Phoenix lets you introspect the passed lambda with proto.
Regards, Martin
participants (2)
-
Martin Häfner
-
Thomas Heller