Boost logo

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:21:05

On Mon, Jul 5, 2010 at 2:18 PM, joel falcou <joel.falcou_at_[hidden]> wrote:
> Jeffrey Lee Hellrung, Jr. wrote:
>> 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".
> If the functor follow the result_of protocol, a  traits can be made to test
> if a functor F can be called with arguments A0,..,An
> with a syntax like can_be_called<F(A0,...,An)>
> Here is a sample implementation:

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;
    // ...

Daniel Walker

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