Subject: Re: [boost] [Review:Algorithms] Order of args to clamp
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2011-09-25 09:36:09
> I don't agree with this reasoning. If "you" (impersonal) don't really
> understand what it means to order objects of different types, why would you
> (or anyone else) define an operator< between objects of those types?
Exactly. How could the value of a string be less than the value of an
int? There are a limited set of cases where defining relations on
different types is meaningful, and by that I mean it preserve the
semantics of an ordering. That set is limited by common type.
> differently, I would think that the existence of an operator< comparing
> objects of different types implies (more often than not) an ordering between
> objects of those types. And if a user implicitly requests the use of this
> operator< through a call to clamp, I don't see why the interface should
> prohibit that.
I don't see how you can possibly define an ordering on values of
unrelated types. Simply saying that its valid because there's an
appropriate < doesn't actually make it true.
Generic programming is based on the idea that you can attribute real
meaning (semantics) with operations in an algorithm even though you
don't know the specific types of their operands. If you can't depend
on < to define a strict order, then you can't guarantee that the clamp
will do the right thing.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk