Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] is_ordered name
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2011-09-24 09:12:06


> With the RV convention change that I proposed on github (always point
> before the first element that is out-of-order with respect to its
> predecessor, rather than the first that is out-of-order with respect
> to its successor), it would be exactly the same, so I think we may be
> stuck with this name, even though I agree that it sounds like it
> should return a bool.

I'm not sure I understand the recommendation. Are you saying that if I write:

auto i = is_ordered(f, l, r)

Then I should have:

is_increasing(f, i);

Or, writing using std algorithms:

auto i = is_sorted_until(f, l, r)
assert(is_sorted(f, i));

> If we were starting from scratch my first impulse would be
> end_of_ordered_prefix(), but that too seems wordier than the ideal.

I think ordered_until is a reasonable name.

On a side note, I think the algorithm can be trivially implemented
using adjacent_find, and should have the same iterator requirements.

return adjacent_find(f, l, not2(pred));

Something like that.

On a technical note, an arbitrary predicate doesn't define an
ordering. You need a Pred to be a relation, a strict weak order. Also,
why not define the algorithm in terms of a natural order? Shouldn't I
be able to write is_ordered(f, l) if the iterator's value is totally
ordered?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk