Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] is_ordered return value
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2011-09-24 12:42:41

Andrew Sutton wrote:
>> 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));

I wondered about this when I looked at the docs and was going to
suggest "the docs should be explicit about which iterator they return";
then I decided that there was (obviously!) only one thing that could
sensibly be returned. I.e. if the input is 1,2,3,4,5,0,42,12 then the
result should be an iterator referring to the 0 element. Surely this
what it does, no?

> 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));

Right, except that that returns the "wrong" iterator of the pair, i.e.
it would return an iterator returning to the 5 in the example above.
You can fix that by incrementing the iterator, but that has to consider
the end case specially.

Regards, Phil.

Boost list run by bdawes at, gregod at, cpdaniel at, john at