[Review:Algorithms] is_ordered behaviour for singleton input, and name

Dear All, The docs for the proposed is_ordered say: The function is_ordered(sequence, predicate) returns the point in the sequence where the predicate does not hold. It does that by comparing adjacent pairs of elements in the sequence to see if the predicate is satisfied. If all adjacent pairs satisfy the predicate, then it will return one past the last element of the sequence. OK. If the sequence has less than two elements, it returns the last element of the sequence. In other words, sequences of length zero and one are considered to be ordered - using any possible criteria. Shouldn't that say "it returns one past the last element"? Also, regarding the name: I would expect any "is_something" function to return a boolean. Since this returns an iterator I would have called it something like find_disorder. (There is a good chance that an iterator is convertible to bool, so one could mistakenly write "if (is_ordered(begin,end)) { ... }".) Regards, Phil.

On Sep 23, 2011, at 9:33 AM, Phil Endecott wrote:
Dear All,
The docs for the proposed is_ordered say:
The function is_ordered(sequence, predicate) returns the point in the sequence where the predicate does not hold. It does that by comparing adjacent pairs of elements in the sequence to see if the predicate is satisfied. If all adjacent pairs satisfy the predicate, then it will return one past the last element of the sequence.
OK.
If the sequence has less than two elements, it returns the last element of the sequence. In other words, sequences of length zero and one are considered to be ordered - using any possible criteria.
Shouldn't that say "it returns one past the last element"?
D'oh! Yes, it should.
Also, regarding the name: I would expect any "is_something" function to return a boolean. Since this returns an iterator I would have called it something like find_disorder. (There is a good chance that an iterator is convertible to bool, so one could mistakenly write "if (is_ordered(begin,end)) { ... }".)
"disorder" doesn't sit quite right with me for some reason. How about "ordered_until", maybe? or "find_unordered" -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki

On Sep 23, 2011 12:39 PM, "Marshall Clow" <mclow.lists@gmail.com> wrote:
"disorder" doesn't sit quite right with me for some reason.
How about "ordered_until", maybe?
or "find_unordered"
+1 for "find_unordered". -Greg
-- Marshall
Marshall Clow Idio Software <mailto:mclow.lists@gmail.com>
A.D. 1517: Martin Luther nails his 95 Theses to the church door and is
promptly moderated down to (-1, Flamebait).
-- Yu Suzuki
_______________________________________________ Unsubscribe & other changes:

Greg Rubino wrote:
On Sep 23, 2011 12:39 PM, "Marshall Clow" <mclow.lists@gmail.com> wrote:
I agree with Phil's concern about is_ordered suggesting that the return type is Boolean.
"disorder" doesn't sit quite right with me for some reason.
How about "ordered_until", maybe?
or "find_unordered"
+1 for "find_unordered".
That's pretty good, but it made me think of the unordered containers, and then that it would find the unordered containers in a sequence. Stupid? Yes. Nevertheless, that was my thought sequence (pun intended). Go with "find_unordered". _____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com ________________________________ IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

On Fri, Sep 23, 2011 at 2:13 PM, Stewart, Robert <Robert.Stewart@sig.com>wrote:
Greg Rubino wrote:
On Sep 23, 2011 12:39 PM, "Marshall Clow" <mclow.lists@gmail.com> wrote:
I agree with Phil's concern about is_ordered suggesting that the return type is Boolean.
"disorder" doesn't sit quite right with me for some reason.
How about "ordered_until", maybe?
or "find_unordered"
+1 for "find_unordered".
That's pretty good, but it made me think of the unordered containers, and then that it would find the unordered containers in a sequence. Stupid? Yes. Nevertheless, that was my thought sequence (pun intended).
That's funny. I thought of unordered_<containers> as well when I read that, but I had a positive reaction to that thought sequence since the semantics of the word 'unordered' are congruent in both contexts. However, I do think that the 'find_' prefix changes the scope to elements of the container rather than the container as a whole (as in unordered_<container>). I actually really like find_disorder(), because it makes it sound more righteous, but find_unordered() is less likely to offend more delicate sensibilities.
Go with "find_unordered".
++1; // syntax error
_____ Rob Stewart robert.stewart@sig.com Software Engineer using std::disclaimer; Dev Tools & Components Susquehanna International Group, LLP http://www.sig.com
________________________________
IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Marshall Clow <mclow.lists@gmail.com> wrote:
On Sep 23, 2011, at 9:33 AM, Phil Endecott wrote:
Also, regarding the name: I would expect any "is_something" function to return a boolean. Since this returns an iterator I would have called it something like find_disorder. (There is a good chance that an iterator is convertible to bool, so one could mistakenly write "if (is_ordered(begin,end)) { ... }".)
"disorder" doesn't sit quite right with me for some reason.
How about "ordered_until", maybe?
or "find_unordered"
Well, I have a find_ordered that does a binary search on a sorted range like std::up|lower_bound and std::equal_range do. I have always felt that std::find should be called std::find_unordered, or at least something in the name should indicate which of those std::algorithms require an ordered range and which don't. Anyway, find_unordered sounds to me like a variant of std::find, which is not what this algorithm is. I think any find_ADJECTIVE would sound like that to me; this case needs a find_NOUN. I spent a few moments trying to think of a noun that means "point at which ordering stops". There probably is one that's better than "disorder". It's not quite a "discontinuity", but maybe there is something like that from maths. I also wondered about a more general word like "failure", since any predicate can be passed. "find_ordering_failure" maybe? Or even just "find_unordering" or "find_unorder". Any thoughts? Regards, Phil.

On 24 Sep 2011, at 01:08, Phil Endecott wrote:
Marshall Clow <mclow.lists@gmail.com> wrote:
On Sep 23, 2011, at 9:33 AM, Phil Endecott wrote:
Also, regarding the name: I would expect any "is_something" function to return a boolean. Since this returns an iterator I would have called it something like find_disorder. (There is a good chance that an iterator is convertible to bool, so one could mistakenly write "if (is_ordered(begin,end)) { ... }".)
"disorder" doesn't sit quite right with me for some reason.
How about "ordered_until", maybe?
or "find_unordered"
Well, I have a find_ordered that does a binary search on a sorted range like std::up|lower_bound and std::equal_range do. I have always felt that std::find should be called std::find_unordered, or at least something in the name should indicate which of those std::algorithms require an ordered range and which don't. Anyway, find_unordered sounds to me like a variant of std::find, which is not what this algorithm is. I think any find_ADJECTIVE would sound like that to me; this case needs a find_NOUN.
I spent a few moments trying to think of a noun that means "point at which ordering stops". There probably is one that's better than "disorder". It's not quite a "discontinuity", but maybe there is something like that from maths. I also wondered about a more general word like "failure", since any predicate can be passed. "find_ordering_failure" maybe? Or even just "find_unordering" or "find_unorder". Any thoughts?
I think the C++ standard uses find_first in a few places, so: find_first_unordered? Getting quite long I realise. Chris

I spent a few moments trying to think of a noun that means "point at which ordering stops". There probably is one that's better than "disorder". It's not quite a "discontinuity", but maybe there is something like that from maths. I also wondered about a more general word like "failure", since any predicate can be passed. "find_ordering_failure" maybe? Or even just "find_unordering" or "find_unorder". Any thoughts?
Isn't this the same as the C++11 is_sorted_until? I think is_* should be a predicate. Unfortunate naming choice for the std, I think. find_sorted_until isn't terrible. Andrew

On Sep 23, 2011, at 7:11 PM, Andrew Sutton wrote:
I spent a few moments trying to think of a noun that means "point at which ordering stops". There probably is one that's better than "disorder". It's not quite a "discontinuity", but maybe there is something like that from maths. I also wondered about a more general word like "failure", since any predicate can be passed. "find_ordering_failure" maybe? Or even just "find_unordering" or "find_unorder". Any thoughts?
Isn't this the same as the C++11 is_sorted_until?
I think is_* should be a predicate. Unfortunate naming choice for the std, I think. find_sorted_until isn't terrible.
Yes, it is. I too think that "is_sorted_until" is an awful name. -- Marshall Marshall Clow Idio Software <mailto:mclow.lists@gmail.com> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki

El 24/09/2011, a las 04:15, Andrew Sutton <asutton.list@gmail.com<mailto:asutton.list@gmail.com>> escribió: I spent a few moments trying to think of a noun that means "point at which ordering stops". There probably is one that's better than "disorder". It's not quite a "discontinuity", but maybe there is something like that from maths. I also wondered about a more general word like "failure", since any predicate can be passed. "find_ordering_failure" maybe? Or even just "find_unordering" or "find_unorder". Any thoughts? Isn't this the same as the C++11 is_sorted_until? Yes! C+11 had is_sorted_until and is_sorted (equivalent to is_sorted_until(first,last)==last). I think the names here should be the same for consistency reasons, and probably the functions should be just aliases to the c++11 ones where applicable. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo ________________________________ Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo. This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at. http://www.tid.es/ES/PAGINAS/disclaimer.aspx

Consider renaming *_of_val to *_equal. So: all_equal none_equal any_equal one_equal Saying _of_val doesn't actually say anything about relation used in the algorithm. Maybe *_equal_to so as not to imply that all_equal means "all values are the same". You might also consider renaming the header to "quantifier.hpp" since all of these algorithms quantify some property of a sequence. EoP also refers to these as quantifiers, IIRC. I left the book at work so I can't check. One a side note, I like the addition of one_of to this group. The implementation is appreciably concise.
participants (7)
-
Andrew Sutton
-
Christopher Jefferson
-
Greg Rubino
-
JOAQUIN M. LOPEZ MUÑOZ
-
Marshall Clow
-
Phil Endecott
-
Stewart, Robert