Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] is_ordered return value
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-09-24 12:57:24


On Sep 24, 2011, at 9:42 AM, Phil Endecott wrote:

> 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.

I agree.
See
        https://github.com/mclow/Boost.Algorithm/issues/2

[ I've already fixed it locally, added tests, and updated the documentation (with examples) ]

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki


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