POV-Ray : Newsgroups : povray.off-topic : An explanation of what next_permutation does Server Time
5 Sep 2024 01:24:30 EDT (-0400)
  An explanation of what next_permutation does (Message 31 to 32 of 32)  
<<< Previous 10 Messages Goto Initial 10 Messages
From: Warp
Subject: Re: An explanation of what next_permutation does
Date: 7 Dec 2009 12:48:48
Message: <4b1d4000@news.povray.org>
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

From: Darren New
Subject: Re: An explanation of what next_permutation does
Date: 7 Dec 2009 13:30:35
Message: <4b1d49cb$1@news.povray.org>
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

<<< Previous 10 Messages Goto Initial 10 Messages

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.