|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r79433 - in trunk: boost/algorithm/cxx11 libs/algorithm/doc libs/algorithm/test
From: marshall_at_[hidden]
Date: 2012-07-11 23:25:59
Author: marshall
Date: 2012-07-11 23:25:58 EDT (Wed, 11 Jul 2012)
New Revision: 79433
URL: http://svn.boost.org/trac/boost/changeset/79433
Log:
Fix behavior of is_sorted_until; thanks to Michel Morin for the report
Text files modified:
trunk/boost/algorithm/cxx11/is_sorted.hpp | 16 ++++++----------
trunk/libs/algorithm/doc/ordered-hpp.qbk | 4 +++-
trunk/libs/algorithm/test/ordered_test.cpp | 8 ++++----
3 files changed, 13 insertions(+), 15 deletions(-)
Modified: trunk/boost/algorithm/cxx11/is_sorted.hpp
==============================================================================
--- trunk/boost/algorithm/cxx11/is_sorted.hpp (original)
+++ trunk/boost/algorithm/cxx11/is_sorted.hpp 2012-07-11 23:25:58 EDT (Wed, 11 Jul 2012)
@@ -46,7 +46,7 @@
ForwardIterator next = first;
while ( ++next != last )
{
- if ( !p ( *first, *next ))
+ if ( p ( *next, *first ))
return next;
first = next;
}
@@ -63,7 +63,7 @@
ForwardIterator is_sorted_until ( ForwardIterator first, ForwardIterator last )
{
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted_until ( first, last, std::less_equal<value_type>());
+ return boost::algorithm::is_sorted_until ( first, last, std::less<value_type>());
}
@@ -125,10 +125,6 @@
return boost::algorithm::is_sorted_until ( boost::begin ( range ), boost::end ( range ));
}
-namespace detail {
- typedef struct { typedef bool type; } bool_;
-};
-
/// \fn is_sorted ( const R &range, Pred p )
/// \return whether or not the entire range R is sorted
/// (according to the comparison predicate 'p').
@@ -173,7 +169,7 @@
bool is_increasing ( ForwardIterator first, ForwardIterator last )
{
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::less_equal<value_type>());
+ return boost::algorithm::is_sorted (first, last, std::less<value_type>());
}
@@ -206,7 +202,7 @@
bool is_decreasing ( ForwardIterator first, ForwardIterator last )
{
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::greater_equal<value_type>());
+ return boost::algorithm::is_sorted (first, last, std::greater<value_type>());
}
/// \fn is_decreasing ( const R &range )
@@ -238,7 +234,7 @@
bool is_strictly_increasing ( ForwardIterator first, ForwardIterator last )
{
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::less<value_type>());
+ return boost::algorithm::is_sorted (first, last, std::less_equal<value_type>());
}
/// \fn is_strictly_increasing ( const R &range )
@@ -269,7 +265,7 @@
bool is_strictly_decreasing ( ForwardIterator first, ForwardIterator last )
{
typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
- return boost::algorithm::is_sorted (first, last, std::greater<value_type>());
+ return boost::algorithm::is_sorted (first, last, std::greater_equal<value_type>());
}
/// \fn is_strictly_decreasing ( const R &range )
Modified: trunk/libs/algorithm/doc/ordered-hpp.qbk
==============================================================================
--- trunk/libs/algorithm/doc/ordered-hpp.qbk (original)
+++ trunk/libs/algorithm/doc/ordered-hpp.qbk 2012-07-11 23:25:58 EDT (Wed, 11 Jul 2012)
@@ -38,7 +38,9 @@
[heading is_sorted_until]
-The function `is_sorted_until(sequence, predicate)` compares each sequential pair of elements in the sequence, checking if they satisfy the predicate. it returns the first element of the sequence that does not satisfy the predicate with its' predecessor. In short, it returns the element in the sequence that is "out of order". If all adjacent pairs satisfy the predicate, then it will return one past the last element of the sequence.
+If `distance(first, last) < 2`, then `is_sorted ( first, last )` returns `last`. Otherwise, it returns the last iterator i in [first,last] for which the range [first,i) is sorted.
+
+In short, it returns the element in the sequence that is "out of order". If the entire sequence is sorted (according to the predicate), then it will return `last`.
``
namespace boost { namespace algorithm {
Modified: trunk/libs/algorithm/test/ordered_test.cpp
==============================================================================
--- trunk/libs/algorithm/test/ordered_test.cpp (original)
+++ trunk/libs/algorithm/test/ordered_test.cpp 2012-07-11 23:25:58 EDT (Wed, 11 Jul 2012)
@@ -54,10 +54,10 @@
BOOST_CHECK ( ba::is_sorted_until ( a_range(strictlyIncreasingValues), std::less<int>()) == boost::end(strictlyIncreasingValues));
// Check for const and non-const arrays
- BOOST_CHECK ( ba::is_sorted_until ( b_e(constantValues), std::less<int>()) != a_end(constantValues));
- BOOST_CHECK ( ba::is_sorted_until ( a_range(constantValues), std::less<int>()) != boost::end(constantValues));
- BOOST_CHECK ( ba::is_sorted_until ( b_e(nonConstantArray), std::less<int>()) != a_end(nonConstantArray));
- BOOST_CHECK ( ba::is_sorted_until ( a_range(nonConstantArray), std::less<int>()) != boost::end(nonConstantArray));
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(constantValues), std::less<int>()) == a_end(constantValues));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(constantValues), std::less<int>()) == boost::end(constantValues));
+ BOOST_CHECK ( ba::is_sorted_until ( b_e(nonConstantArray), std::less<int>()) == a_end(nonConstantArray));
+ BOOST_CHECK ( ba::is_sorted_until ( a_range(nonConstantArray), std::less<int>()) == boost::end(nonConstantArray));
BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues), std::less<int>()) == &randomValues[2] );
BOOST_CHECK ( ba::is_sorted_until ( b_e(randomValues)) == &randomValues[2] );
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk