|
![](/i/fill.gif) |
scott <sco### [at] scott com> 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
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> from it, and stick to operator< exclusively, if possible.
And other than readability, compilers these days are smart enough to
generate the same optimal[1] code for it regardless.
[1] Funny how "optimized" no longer means what it used to, isn't it?
--
Darren New, San Diego CA, USA (PST)
Human nature dictates that toothpaste tubes spend
much longer being almost empty than almost full.
Post a reply to this message
|
![](/i/fill.gif) |