Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] is_ordered return value
From: Andrew Sutton (asutton.list_at_[hidden])
Date: 2011-09-24 14:07:19


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

I'm almost 100% certain it does this, but I'm not looking at the
standard right now. If it turns out that it doesn't do this then I
would say that it's a specification error.

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

Ah. I see it now. I forgot which iterator adjacent_find returns. So:

auto i = adjacent_find(f, l, not2(pred));
return i == l ? l : next(i);


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