Boost logo

Boost :

Subject: Re: [boost] [function_types] is there an equivalent for functors?
From: Edd Dawson (lists_at_[hidden])
Date: 2010-07-05 14:33:30

On 7/5/2010 6:59 PM, Jeffrey Lee Hellrung, Jr. wrote:
> On 7/5/2010 10:46 AM, Edd Dawson wrote:
>> Hi all,
>> I'm looking for code that does what
>> boost::function_types::parameter_types does but for functors. Support
>> for things such as boost::bind/lambda/function/signals(1&2)/etc and the
>> standard binders and adaptors would be nice.

> If you want restrict yourself to monomorphic function objects, then it
> might be possible, but I don't know of a generic way to obtain the
> information you're seeking.

Ah yes, I didn't mean to imply that I was seeking a truly generic solution. A
"sanctioned" collection of template specializations for common functor types
would be fine.

The standard function objects have internal typedefs such as argument_type,
second_argument_type and so on for this kind of deduction. Some of the boost
functor libraries follow this convention and extend it to cope with more than
two parameters... but others don't :(

Actually, I don't strictly *need* such a facility, but it would my little
library a bit nicer to use e.g.

connect(slider, SIGNAL(valueChanged(int)), bind(&on_slide, ref(value), _1)));
connectx<void (int)>(slider, SIGNAL(valueChanged(int)),
                              bind(&on_slide, ref(value), _1));

(it's for connecting Qt signals to functions/functors without going through the
extra bother of the moc step at build time).

> You can, however, get away with querying whether a function object can
> be called with a specific signature, though the machinery to do this is
> relatively complex. I think something working is found in Boost.Proto as
> "can_be_called".

Unfortunately, my problem is that I'm handed an almost arbitrary functor and
need to be able to deduce the parameter types from the functor's type alone.

This is because Qt's "meta machinery" forces me eventually to cast a bunch of
void*s to pointers whose types are given by the functor parameters, in order to
actually call the functor.

Without having a database of types upfront and employing an exponential
algorithm, can_be_called is probably not going to get me what I want, right?



Boost list run by bdawes at, gregod at, cpdaniel at, john at