Boost logo

Boost :

From: Marco Costalba (mcostalba_at_[hidden])
Date: 2008-05-19 13:37:09


On Mon, May 19, 2008 at 4:26 PM, Daniel Walker
<daniel.j.walker_at_[hidden]> wrote:
> a placeholder. Placeholders indicate a template parameter in the
> function's argument list (not an unspecified function object outside
> the argument list). Actually, come to think of it, _1(_1, _1) would
> probably not be possible because it doesn't encode the type of a
> polymorphic function object, so there's no way for the compiler to use
> that type's set of overloaded operator()s later on at the call site.
> _1(_1,_1) is type erasure again and that breaks polymorphic function
> objects.
>

Well, the first _1 is intended to be the return type, not the polymorphic type.

It's _1(_1, _1) because plus and minus return T: T plus(T, T), T minus(T, T)

So it's bool (T) because is_positive and is_negative return a bool.

Actually I think there is no way to create a polymorphic functor
wrapper, but anyway it's the logical extension of function signatures
in the polymorphic world because function signatures do not imply
_any_ algorithm or functionality apart from arguments and return type.

So a poly signature should define return type and arguments ONLY.
Because here we talk about templates, i.e. family of types and not a
single type we can only specify argument arity and when argument
types should be the same, as in plus, or different as _3(_1, _2)

I would think overload_set is based on the concept of wrapping a
function (call it type erasure), but when you assign plus(_1,_1) there
is nothing to wrap, just use plus instantiated by compiler according
to the calling sites arguments.

If you need a generic fallback it is better to let overload_set derive
directly from plus() and you have what you need.

Comments?

Thanks
Marco


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk