|
Boost : |
Subject: Re: [boost] [function_types] is there an equivalent for functors?
From: Daniel Walker (daniel.j.walker_at_[hidden])
Date: 2010-07-05 15:53:19
On Mon, Jul 5, 2010 at 3:36 PM, Edd Dawson <lists_at_[hidden]> wrote:
> On 7/5/2010 8:21 PM, Daniel Walker wrote:
>>
>> And if you know a signature of a functor, you can use function_types
>> directly with the signature. For example,
>>
>> template<typename Signature>
>> void f(const boost::function<Signature> &f)
>> {
>> using boost::function_types::parameter_types;
>> using boost::function_types::function_arity;
>>
>> typedef typename parameter_types<Signature>::type params; // an mpl
>> sequence
>> const std::size_t arity = function_arity<Signature>::value;
>> // ...
>> }
>
> 100 bonus points for implementing boost::bind support for me :)
>
No prob. Yeah, boost::function can store boost::bind objects... if you
know the signature.
Also, another thought, if the call operators on your function objects
are not overloaded, you can do something like the following without
having to know the signature.
template<typename Functor, typename CallOperator>
void f(const Functor &f, CallOperator)
{
using boost::function_types::parameter_types;
using boost::function_types::function_arity;
typedef typename parameter_types<CallOperator>::type params; // an
mpl sequence
const std::size_t arity = function_arity<CallOperator>::value;
// ...
}
struct F {
void operator()(int) {}
};
int main()
{
f(F(), &F::operator());
}
Daniel Walker
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk