[Algorithm] Incorrect behavior of is_sorted_until (predicate version)

Hi Marshall, Suppose we have an array int ar[5] = {1, 2, 2, 2, 2}; Then, `is_sorted_until(ar, ar + 5, std::less<int>())` should return `ar`'s end pointer. But it gives `ar + 2`. To fix this, change line 49 of is_sorted.hpp if ( !p ( *first, *next )) return next; to if ( p ( *next, *first )) return next; After fixing it, don't forget to change the predicate used in non-predicate version of is_sorted_until ;) Spotted by "clang-cxx11-r159746" test runner. Regards, Michel

On Jul 11, 2012, at 4:53 PM, Michel Morin wrote:
Hi Marshall,
Suppose we have an array int ar[5] = {1, 2, 2, 2, 2}; Then, `is_sorted_until(ar, ar + 5, std::less<int>())` should return `ar`'s end pointer. But it gives `ar + 2`.
Michel, Thanks for the bug report. Originally, I thought that you were mistaken; the code is doing exactly what I intended it to do. Eventually, I came around to your point of view; my code was correctly written, but my understanding of what it should do was lacking. I'll try to fix it tonight. Sigh. -- 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
participants (2)
-
Marshall Clow
-
Michel Morin