|
Boost : |
From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-05-17 03:42:06
From: John Maddock <John_Maddock_at_[hidden]
> template <class F>
> struct make_functor_ind;
>
> template <class T>
> struct make_functor_ind<T*>
> {
> typedef T type;
> typedef const T& cast_type;
> };
>
> template <class R, class A>
> struct make_functor_ind<R (*)(A)>
> {
> typedef R(*type)(A);
> typedef R(*cast_type)(A);
> };
>
Yes, I came to a very similar conclusion, except that I called
the cast_type param_type and put it into unary_traits. In fact,
I've shoved the extra indirection into the traits so that users
of the traits (e.g., not1) need not be aware of it.
I justify param_type as "the type used to pass the function
object as an argument", and declare my functors' constructors like
this:
explicit unary_negate(typename unary_traits<Predicate>::param_type x)
...
and my helper function like this:
template <class Predicate>
unary_negate<Predicate> not1(const Predicate &pred)
{
return unary_negate<Predicate>(
(typename unary_traits<Predicate>::param_type)pred);
}
g++ does not require the cast, and I have been experimenting with ways
to dispense with it for Borland, but have not come up with anything
yet.
I've updated the vault with a new version, but will continue to
experiment to see if I can improve on it. Any ideas welcome.
Thanks for your help,
Mark
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk