Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-05-30 08:28:13


Hello Markus,

Markus Werle wrote:
> Hi!
>
> What I want to achieve: automatically build
> a boost::function from a bind expression
> without having to specifiy the signature.

the function objects returned from boost::bind have a templatized
operator(), so they don't really have a signature.

When you assign such a thing to Boost.Function it instantiates
operator() for a given signature and removes the type.

You can't turn a template into code without instantiating it and you
can't store a template - only instances thereof (there is no runtime
representation - stuff like this would require a (partially) interpreted
language).

>>From what I understand in the boost::bind code
> it is not possible to extract the signature, arity or
> return type information from an object returned by boost::bind.

Yes, and for signature it's impossible to implement (in general) because
what's bound might again be a function object with a templatized
operator(). Plus the result type might be a function of the argument types.

> So I have no idea, how to write code that allows the
> registration of arbitrary function pointers as boost::function
> objects depending on the argument list.

So I guess you want something like

     some_class c;
     c.register( & some_function );
     c.register( & another_function );

, right?

> Any hint to possible solutions appreciated.

In either case the recipe is to have the 'register' template generate
some kind of "invoker" based on the signature, so you can "bury" the
type in the invoker and forget about it once the invoker (which always
has the same type) is stored. Here's an example that shows the exact case:

     $(CVS_HEAD)/libs/function_types/example/interpreter*

This one might also be interesting to you:

     $(CVS_HEAD)/fusion/example/cookbook/do_the_bind.cpp

Regards,
Tobias


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