|
|
scott <sco### [at] scottcom> wrote:
> > And in why is it 'not (x < y)" rather than 'x >= y'?"
> Aren't they the same? (btw the only reason I can see that you would use the
> first one is if the types being used don't have the >= operator defined).
> IIRC quite a lot of functions and libraries only assume that one of those
> operators is implemented, so that's probably why you'll see stuff like that.
It is customary in the C++ standard library to demand as little as
possible from the types being handled. Anything requiring comparison of
element usually demands only operator< from the elements (if the algorithm
can be feasibly be implemented using that operator only).
If you are making a generic algorithm or data container which compares
elements, it's also usually a good idea to demand as little as possible
from it, and stick to operator< exclusively, if possible.
--
- Warp
Post a reply to this message
|
|