|
Boost : |
Subject: Re: [boost] determine first arg of callable
From: Oliver Kowalke (oliver.kowalke_at_[hidden])
Date: 2013-05-15 09:13:12
2013/5/15 Mathias Gaunard <mathias.gaunard_at_[hidden]>
> On 15/05/13 10:35, Oliver Kowalke wrote:
>
>> I need some help to extract the type of a callable which is passed as
>> argument to the ctor of X.
>>
>> struct X
>> {
>> template< typename Fn >
>> X( Fn fn) {
>> ... code which evaluates Fn and extracts the type of the first arg
>> of Fn
>> }
>> };
>>
>
> You can't do that.
> Just change your code to not require it.
>
that is not possible
at least what I can do is to overload the ctor:
template< typename Arg >
X( void(*fn)( Arg &) ) {...}
template< typename Arg >
X( boost::function< void( Arg &) > fn) {...}
ctor is called then:
X x1( g); // OK
A a;
boost::function< void( Y< char > &) > f1=boost::bind( & A::operator(), a,
_1);
X x2( f1);
boost::function< void( Y< int > &) > f2=boost::bind( g, _1);
X x3( f2);
For function pointer it's OK - but the code using function<> and bind()
looks a little bit clumsy:
X x2(boost::bind( & A::operator(), a, _1)); // will not compile
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk