Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79538 - in branches/release: boost/algorithm boost/algorithm/cxx11 boost/algorithm/searching boost/algorithm/searching/detail libs/algorithm/doc libs/algorithm/test libs/algorithm/test/search_test_data
From: marshall_at_[hidden]
Date: 2012-07-15 12:28:36


Author: marshall
Date: 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
New Revision: 79538
URL: http://svn.boost.org/trac/boost/changeset/79538

Log:
Merge Boost.Algorithm changes to release; Fixes #7104
Added:
   branches/release/libs/algorithm/test/hex_test4.cpp
      - copied unchanged from r79009, /trunk/libs/algorithm/test/hex_test4.cpp
   branches/release/libs/algorithm/test/search_test4.cpp
      - copied unchanged from r79380, /trunk/libs/algorithm/test/search_test4.cpp
Properties modified:
   branches/release/boost/algorithm/cxx11/is_sorted.hpp (contents, props changed)
   branches/release/boost/algorithm/hex.hpp (contents, props changed)
   branches/release/boost/algorithm/searching/ (props changed)
   branches/release/boost/algorithm/searching/boyer_moore.hpp (contents, props changed)
   branches/release/boost/algorithm/searching/boyer_moore_horspool.hpp (contents, props changed)
   branches/release/boost/algorithm/searching/detail/bm_traits.hpp (props changed)
   branches/release/boost/algorithm/searching/detail/debugging.hpp (props changed)
   branches/release/boost/algorithm/searching/knuth_morris_pratt.hpp (contents, props changed)
   branches/release/libs/algorithm/doc/ordered-hpp.qbk (contents, props changed)
   branches/release/libs/algorithm/test/ (props changed)
   branches/release/libs/algorithm/test/Jamfile.v2 (contents, props changed)
   branches/release/libs/algorithm/test/all_of_test.cpp (props changed)
   branches/release/libs/algorithm/test/any_of_test.cpp (props changed)
   branches/release/libs/algorithm/test/clamp_test.cpp (props changed)
   branches/release/libs/algorithm/test/copy_n_test1.cpp (props changed)
   branches/release/libs/algorithm/test/empty_search_test.cpp (props changed)
   branches/release/libs/algorithm/test/find_if_not_test1.cpp (props changed)
   branches/release/libs/algorithm/test/hex_fail1.cpp (props changed)
   branches/release/libs/algorithm/test/hex_test1.cpp (props changed)
   branches/release/libs/algorithm/test/hex_test2.cpp (props changed)
   branches/release/libs/algorithm/test/hex_test3.cpp (props changed)
   branches/release/libs/algorithm/test/iota_test1.cpp (props changed)
   branches/release/libs/algorithm/test/is_partitioned_test1.cpp (props changed)
   branches/release/libs/algorithm/test/is_permutation_test1.cpp (props changed)
   branches/release/libs/algorithm/test/none_of_test.cpp (props changed)
   branches/release/libs/algorithm/test/one_of_test.cpp (props changed)
   branches/release/libs/algorithm/test/ordered_test.cpp (contents, props changed)
   branches/release/libs/algorithm/test/partition_copy_test1.cpp (props changed)
   branches/release/libs/algorithm/test/partition_point_test1.cpp (props changed)
   branches/release/libs/algorithm/test/search_fail1.cpp (props changed)
   branches/release/libs/algorithm/test/search_fail2.cpp (props changed)
   branches/release/libs/algorithm/test/search_fail3.cpp (props changed)
   branches/release/libs/algorithm/test/search_test1.cpp (props changed)
   branches/release/libs/algorithm/test/search_test2.cpp (props changed)
   branches/release/libs/algorithm/test/search_test3.cpp (props changed)
   branches/release/libs/algorithm/test/search_test_data/0001.corpus (props changed)
   branches/release/libs/algorithm/test/search_test_data/0001b.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0001e.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0001f.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0001n.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0002b.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0002e.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0002f.pat (props changed)
   branches/release/libs/algorithm/test/search_test_data/0002n.pat (props changed)
Text files modified:
   branches/release/boost/algorithm/cxx11/is_sorted.hpp | 16 ++++-------
   branches/release/boost/algorithm/hex.hpp | 18 ++++--------
   branches/release/boost/algorithm/searching/boyer_moore.hpp | 4 +-
   branches/release/boost/algorithm/searching/boyer_moore_horspool.hpp | 57 ++++++++++++++++++++++++++++++++++++++-
   branches/release/boost/algorithm/searching/knuth_morris_pratt.hpp | 57 ++++++++++++++++++++++++++++++++++++++-
   branches/release/libs/algorithm/doc/ordered-hpp.qbk | 4 ++
   branches/release/libs/algorithm/test/Jamfile.v2 | 2 +
   branches/release/libs/algorithm/test/ordered_test.cpp | 8 ++--
   8 files changed, 133 insertions(+), 33 deletions(-)

Modified: branches/release/boost/algorithm/cxx11/is_sorted.hpp
==============================================================================
--- branches/release/boost/algorithm/cxx11/is_sorted.hpp (original)
+++ branches/release/boost/algorithm/cxx11/is_sorted.hpp 2012-07-15 12:28:35 EDT (Sun, 15 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: branches/release/boost/algorithm/hex.hpp
==============================================================================
--- branches/release/boost/algorithm/hex.hpp (original)
+++ branches/release/boost/algorithm/hex.hpp 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
@@ -51,14 +51,10 @@
     \brief Thrown when the input sequence unexpectedly ends
     
 */
-struct hex_decode_error: virtual boost::exception, virtual std::exception {};
-struct not_enough_input : public hex_decode_error {};
-struct non_hex_input : public hex_decode_error {
- non_hex_input ( char ch ) : bad_char ( ch ) {}
- char bad_char;
-private:
- non_hex_input (); // don't allow creation w/o a char
- };
+struct hex_decode_error : virtual boost::exception, virtual std::exception {};
+struct not_enough_input : virtual hex_decode_error {};
+struct non_hex_input : virtual hex_decode_error {};
+typedef boost::error_info<struct bad_char_,char> bad_char;
 
 namespace detail {
 /// \cond DOXYGEN_HIDE
@@ -77,7 +73,7 @@
         if ( c >= '0' && c <= '9' ) return c - '0';
         if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10;
         if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
- BOOST_THROW_EXCEPTION (non_hex_input (c));
+ BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c));
         return 0; // keep dumb compilers happy
         }
     
@@ -227,10 +223,8 @@
 // If we run into the terminator while decoding, we will throw a
 // malformed input exception. It would be nicer to throw a 'Not enough input'
 // exception - but how much extra work would that require?
-// I just make up an "end iterator" which we will never get to -
-// two Ts per byte of the output type.
     while ( *ptr )
- out = detail::decode_one ( ptr, ptr + 2 * sizeof(OutputType), out );
+ out = detail::decode_one ( ptr, (const T *) NULL, out );
     return out;
     }
 

Modified: branches/release/boost/algorithm/searching/boyer_moore.hpp
==============================================================================
--- branches/release/boost/algorithm/searching/boyer_moore.hpp (original)
+++ branches/release/boost/algorithm/searching/boyer_moore.hpp 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
@@ -223,7 +223,7 @@
     corpusIter boyer_moore_search (
         corpusIter corpus_first, corpusIter corpus_last, const PatternRange &pattern )
     {
- typedef typename boost::range_iterator<PatternRange> pattern_iterator;
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
         boyer_moore<pattern_iterator> bm ( boost::begin(pattern), boost::end (pattern));
         return bm ( corpus_first, corpus_last );
     }
@@ -242,7 +242,7 @@
     typename boost::range_iterator<CorpusRange>::type
     boyer_moore_search ( CorpusRange &corpus, const PatternRange &pattern )
     {
- typedef typename boost::range_iterator<PatternRange> pattern_iterator;
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
         boyer_moore<pattern_iterator> bm ( boost::begin(pattern), boost::end (pattern));
         return bm (boost::begin (corpus), boost::end (corpus));
     }

Modified: branches/release/boost/algorithm/searching/boyer_moore_horspool.hpp
==============================================================================
--- branches/release/boost/algorithm/searching/boyer_moore_horspool.hpp (original)
+++ branches/release/boost/algorithm/searching/boyer_moore_horspool.hpp 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
@@ -84,6 +84,11 @@
             return this->do_search ( corpus_first, corpus_last );
             }
             
+ template <typename Range>
+ typename boost::range_iterator<Range>::type operator () ( Range &r ) const {
+ return (*this) (boost::begin(r), boost::end(r));
+ }
+
     private:
 /// \cond DOXYGEN_HIDE
         patIter pat_first, pat_last;
@@ -119,6 +124,9 @@
 // \endcond
         };
 
+/* Two ranges as inputs gives us four possibilities; with 2,3,3,4 parameters
+ Use a bit of TMP to disambiguate the 3-argument templates */
+
 /// \fn boyer_moore_horspool_search ( corpusIter corpus_first, corpusIter corpus_last,
 /// patIter pat_first, patIter pat_last )
 /// \brief Searches the corpus for the pattern.
@@ -130,10 +138,55 @@
 ///
     template <typename patIter, typename corpusIter>
     corpusIter boyer_moore_horspool_search (
- corpusIter corpus_first, corpusIter corpus_last,
- patIter pat_first, patIter pat_last ) {
+ corpusIter corpus_first, corpusIter corpus_last,
+ patIter pat_first, patIter pat_last )
+ {
         boyer_moore_horspool<patIter> bmh ( pat_first, pat_last );
         return bmh ( corpus_first, corpus_last );
+ }
+
+ template <typename PatternRange, typename corpusIter>
+ corpusIter boyer_moore_horspool_search (
+ corpusIter corpus_first, corpusIter corpus_last, const PatternRange &pattern )
+ {
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
+ boyer_moore_horspool<pattern_iterator> bmh ( boost::begin(pattern), boost::end (pattern));
+ return bmh ( corpus_first, corpus_last );
+ }
+
+ template <typename patIter, typename CorpusRange>
+ typename boost::lazy_disable_if_c<
+ boost::is_same<CorpusRange, patIter>::value, typename boost::range_iterator<CorpusRange> >
+ ::type
+ boyer_moore_horspool_search ( CorpusRange &corpus, patIter pat_first, patIter pat_last )
+ {
+ boyer_moore_horspool<patIter> bmh ( pat_first, pat_last );
+ return bm (boost::begin (corpus), boost::end (corpus));
+ }
+
+ template <typename PatternRange, typename CorpusRange>
+ typename boost::range_iterator<CorpusRange>::type
+ boyer_moore_horspool_search ( CorpusRange &corpus, const PatternRange &pattern )
+ {
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
+ boyer_moore_horspool<pattern_iterator> bmh ( boost::begin(pattern), boost::end (pattern));
+ return bmh (boost::begin (corpus), boost::end (corpus));
+ }
+
+
+ // Creator functions -- take a pattern range, return an object
+ template <typename Range>
+ boost::algorithm::boyer_moore_horspool<typename boost::range_iterator<const Range>::type>
+ make_boyer_moore_horspool ( const Range &r ) {
+ return boost::algorithm::boyer_moore_horspool
+ <typename boost::range_iterator<const Range>::type> (boost::begin(r), boost::end(r));
+ }
+
+ template <typename Range>
+ boost::algorithm::boyer_moore_horspool<typename boost::range_iterator<Range>::type>
+ make_boyer_moore_horspool ( Range &r ) {
+ return boost::algorithm::boyer_moore_horspool
+ <typename boost::range_iterator<Range>::type> (boost::begin(r), boost::end(r));
         }
 
 }}

Modified: branches/release/boost/algorithm/searching/knuth_morris_pratt.hpp
==============================================================================
--- branches/release/boost/algorithm/searching/knuth_morris_pratt.hpp (original)
+++ branches/release/boost/algorithm/searching/knuth_morris_pratt.hpp 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
@@ -79,6 +79,11 @@
             return do_search ( corpus_first, corpus_last, k_corpus_length );
             }
     
+ template <typename Range>
+ typename boost::range_iterator<Range>::type operator () ( Range &r ) const {
+ return (*this) (boost::begin(r), boost::end(r));
+ }
+
     private:
 /// \cond DOXYGEN_HIDE
         patIter pat_first, pat_last;
@@ -179,6 +184,9 @@
         };
 
 
+/* Two ranges as inputs gives us four possibilities; with 2,3,3,4 parameters
+ Use a bit of TMP to disambiguate the 3-argument templates */
+
 /// \fn knuth_morris_pratt_search ( corpusIter corpus_first, corpusIter corpus_last,
 /// patIter pat_first, patIter pat_last )
 /// \brief Searches the corpus for the pattern.
@@ -190,10 +198,55 @@
 ///
     template <typename patIter, typename corpusIter>
     corpusIter knuth_morris_pratt_search (
- corpusIter corpus_first, corpusIter corpus_last,
- patIter pat_first, patIter pat_last ) {
+ corpusIter corpus_first, corpusIter corpus_last,
+ patIter pat_first, patIter pat_last )
+ {
         knuth_morris_pratt<patIter> kmp ( pat_first, pat_last );
         return kmp ( corpus_first, corpus_last );
+ }
+
+ template <typename PatternRange, typename corpusIter>
+ corpusIter knuth_morris_pratt_search (
+ corpusIter corpus_first, corpusIter corpus_last, const PatternRange &pattern )
+ {
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
+ knuth_morris_pratt<pattern_iterator> kmp ( boost::begin(pattern), boost::end (pattern));
+ return kmp ( corpus_first, corpus_last );
+ }
+
+ template <typename patIter, typename CorpusRange>
+ typename boost::lazy_disable_if_c<
+ boost::is_same<CorpusRange, patIter>::value, typename boost::range_iterator<CorpusRange> >
+ ::type
+ knuth_morris_pratt_search ( CorpusRange &corpus, patIter pat_first, patIter pat_last )
+ {
+ knuth_morris_pratt<patIter> kmp ( pat_first, pat_last );
+ return kmp (boost::begin (corpus), boost::end (corpus));
+ }
+
+ template <typename PatternRange, typename CorpusRange>
+ typename boost::range_iterator<CorpusRange>::type
+ knuth_morris_pratt_search ( CorpusRange &corpus, const PatternRange &pattern )
+ {
+ typedef typename boost::range_iterator<const PatternRange>::type pattern_iterator;
+ knuth_morris_pratt<pattern_iterator> kmp ( boost::begin(pattern), boost::end (pattern));
+ return kmp (boost::begin (corpus), boost::end (corpus));
+ }
+
+
+ // Creator functions -- take a pattern range, return an object
+ template <typename Range>
+ boost::algorithm::knuth_morris_pratt<typename boost::range_iterator<const Range>::type>
+ make_knuth_morris_pratt ( const Range &r ) {
+ return boost::algorithm::knuth_morris_pratt
+ <typename boost::range_iterator<const Range>::type> (boost::begin(r), boost::end(r));
+ }
+
+ template <typename Range>
+ boost::algorithm::knuth_morris_pratt<typename boost::range_iterator<Range>::type>
+ make_knuth_morris_pratt ( Range &r ) {
+ return boost::algorithm::knuth_morris_pratt
+ <typename boost::range_iterator<Range>::type> (boost::begin(r), boost::end(r));
         }
 }}
 

Modified: branches/release/libs/algorithm/doc/ordered-hpp.qbk
==============================================================================
--- branches/release/libs/algorithm/doc/ordered-hpp.qbk (original)
+++ branches/release/libs/algorithm/doc/ordered-hpp.qbk 2012-07-15 12:28:35 EDT (Sun, 15 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: branches/release/libs/algorithm/test/Jamfile.v2
==============================================================================
--- branches/release/libs/algorithm/test/Jamfile.v2 (original)
+++ branches/release/libs/algorithm/test/Jamfile.v2 2012-07-15 12:28:35 EDT (Sun, 15 Jul 2012)
@@ -16,6 +16,7 @@
      [ run search_test1.cpp : : : : search_test1 ]
      [ run search_test2.cpp : : : : search_test2 ]
      [ run search_test3.cpp : : : : search_test3 ]
+ [ run search_test4.cpp : : : : search_test4 ]
      [ compile-fail search_fail1.cpp : : : : ]
      [ compile-fail search_fail2.cpp : : : : ]
      [ compile-fail search_fail3.cpp : : : : ]
@@ -43,6 +44,7 @@
      [ run hex_test1.cpp : : : : hex_test1 ]
      [ run hex_test2.cpp : : : : hex_test2 ]
      [ run hex_test3.cpp : : : : hex_test3 ]
+ [ run hex_test4.cpp : : : : hex_test4 ]
          [ compile-fail hex_fail1.cpp ]
    ;
 }

Modified: branches/release/libs/algorithm/test/ordered_test.cpp
==============================================================================
--- branches/release/libs/algorithm/test/ordered_test.cpp (original)
+++ branches/release/libs/algorithm/test/ordered_test.cpp 2012-07-15 12:28:35 EDT (Sun, 15 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