|
Boost : |
Subject: Re: [boost] determine first arg of callable
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-05-15 10:23:09
On Wed, May 15, 2013 at 6:07 PM, Oliver Kowalke <oliver.kowalke_at_[hidden]>wrote:
>
> OK - some simple code:
>
> struct B
> {
> virtual void run() = 0;
> };
>
> template< typename Fn >
> struct D : public B
> {
> Fn fn;
>
> D( Fn fn_) : fn( fn_) {}
>
> void run() { fn(...) } // argument construction omitted
> };
>
> struct X
> {
> B * b;
>
> template< typename Fn >
> X( Fn fn) : b( 0)
> {
> b = new D< Fn >( fn);
> }
>
> void run() { b->run(); }
> };
>
> Constraints to Fn: returns void and has only one argument.
> I need to know in X::X() or D::run() what's the first and only argument of
> Fn.
>
It doesn't follow from the code above. If D is the same for all Fns then I
don't see how D can discover the type (and value) of the argument to pass.
The way your design looks it seems the other way around - it is D who
defines the argument type and value, and Fn should be able to accept it.
> I believe the problem should be solvable - for function pointers it is
> easy, X() could be overloaded with function<>.
> The only remaining issue are objects created by bind() and passed to the
> ctor - I thought overloading X() with the type returned by bind() should
> work?!
>
No, bind function object types do not have the argument types. These types
are not known until the function object is actually invoked. The only types
you will find is the bound function object type and bound argument values
types (and the latter may differ from the actual argument types, BTW).
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk