$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: David Abrahams (dave_at_[hidden])
Date: 2002-11-22 07:22:57
Sylvain Pion <Sylvain.Pion_at_[hidden]> writes:
> On Thu, Nov 21, 2002 at 11:03:58AM -0500, David Abrahams wrote:
>> Do we have any precedent for ways to find out what the arity and
>> argument types of an arbitrary function object is (I'm not talking
>> about function pointers, here, but "functors")?
>
> There's one in the CGAL library.  There, the kernel functors look like :
>
> template <typename K>
> class Angle_2
> {
>     typedef typename K::Point_2 Point_2;
> public:
>     typedef Angle            result_type;
>     typedef Arity_tag< 3 >   Arity;
>
>     Angle
>     operator()(const Point_2& p, const Point_2& q, const Point_2& r) const
>     { return angle(p, q, r); }
> };
>
>
> So there is an "Arity" nested type in each functor.  When there are several
> operators() with different arities, the Arity type is still provided
> (so that generic adapters can be used), but then it only acts as a default.
> You can change the arity, when the default is not what you want, with an
> adapter Set_arity<F, new_arity>.
>
> Access to the arity is supposed to be done with an Arity_traits<>, so that
> it can be made to work with std:: functors as well, e.g. :
>
> template < class T >
> struct Arity_traits< std::plus< T > > {
>   typedef Arity_tag< 2 > Arity;
> };
And that's supposed to be spelled:
 template < class T >
 struct Arity_traits< std::plus< T > > {
   typedef Arity_tag< 2 > type;
 };
So that it can be used with MPL. But that's beside the point. Finding
the arity is just one small piece of the puzzle. I need the types of
all the arguments.
-- 
                       David Abrahams
   dave_at_[hidden] * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution