|
Boost : |
Subject: Re: [boost] determine first arg of callable
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2013-05-15 10:07:48
13/5/15 Andrey Semashev <andrey.semashev_at_[hidden]>
> On Wed, May 15, 2013 at 5:38 PM, Oliver Kowalke <oliver.kowalke_at_[hidden]
> >wrote:
>
> >
> > the class has to accept a callable object (function pointer or functor) -
> > what is known is that it does return void and takes one argument.
> > this is not a design decision, it is required by the user.
> > as I showed in my example it can be solved - maybe a solution would be to
> > overload the ctor with the type returned by boost::bind().
>
>
> The bind function objects do not have a single operator(), and their
> operators() are templates.
>
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.
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?!
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk