From eccac19108e555b48454db171422e74e6904dcb9 Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Fri, 7 Oct 2016 23:03:40 -0500 Subject: [PATCH 01/16] Add, and update, documentation build targets. --- doc/Jamfile.v2 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index 6af1129..ef482ec 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -44,3 +44,13 @@ boostbook standalone toc.max.depth=2 generate.section.toc.level=1 ; + +############################################################################### +alias boostdoc + : algorithm ../string/doc/string_algo.xml + : + : autodoc ../string/doc//autodoc + : ; +explicit boostdoc ; +alias boostrelease ; +explicit boostrelease ; From 303ff13b863c95a11f8befac18ff13783ac214b1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 12 Oct 2016 22:22:30 +0300 Subject: [PATCH 02/16] Delete duplicate version os is_palindrome --- include/boost/algorithm/is_palindrome.hpp | 41 +++++------------------ 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/include/boost/algorithm/is_palindrome.hpp b/include/boost/algorithm/is_palindrome.hpp index 8649ad6..bd8b9f9 100644 --- a/include/boost/algorithm/is_palindrome.hpp +++ b/include/boost/algorithm/is_palindrome.hpp @@ -36,7 +36,7 @@ namespace boost { namespace algorithm { /// For other sequences function will return false. /// Complexity: O(N). template -bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p ) +bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p) { if(begin == end) { @@ -64,7 +64,7 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi /// \return true if the entire sequence is palindrome /// /// \param begin The start of the input sequence -/// \param end One past the end of the input sequence +/// \param end One past the end of the input sequence /// /// \note This function will return true for empty sequences and for palindromes. /// For other sequences function will return false. @@ -72,26 +72,8 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi template bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end) { - if(begin == end) - { - return true; - } - - --end; - while(begin != end) - { - if(!(*begin == *end)) - { - return false; - } - ++begin; - if(begin == end) - { - break; - } - --end; - } - return true; + return is_palindrome(begin, end, + std::equal_to::value_type> ()); } /// \fn is_palindrome ( const R& range ) @@ -123,7 +105,6 @@ bool is_palindrome(const R& range, Predicate p) return is_palindrome(boost::begin(range), boost::end(range), p); } - /// \fn is_palindrome ( const char* str ) /// \return true if the entire sequence is palindrome /// @@ -134,14 +115,11 @@ bool is_palindrome(const R& range, Predicate p) /// Complexity: O(N). bool is_palindrome(const char* str) { - if(str == nullptr) - { - return true; - } + if(!str) + return true; return is_palindrome(str, str + strlen(str)); } - /// \fn is_palindrome ( const char* str, Predicate p ) /// \return true if the entire sequence is palindrome /// @@ -154,13 +132,10 @@ bool is_palindrome(const char* str) template bool is_palindrome(const char* str, Predicate p) { - if(str == nullptr) - { - return true; - } + if(!str) + return true; return is_palindrome(str, str + strlen(str), p); } - }} #endif // BOOST_ALGORITHM_IS_PALINDROME_HPP From 8dfebc4580a16ff4083a5585827c5e9be40dd049 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 25 Oct 2016 14:31:26 +0300 Subject: [PATCH 03/16] Added README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..92a9140 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ + + Coverity Scan Build Status + From efd7a8b54426e7d5e1eb0e572103875e1981c7c3 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 26 Oct 2016 11:22:37 -0700 Subject: [PATCH 04/16] Updated the docs for the searchers to reflect the new interface, and added rationale for the change. --- doc/boyer_moore.qbk | 20 +++++++++++++++++--- doc/boyer_moore_horspool.qbk | 20 +++++++++++++++++--- doc/knuth_morris_pratt.qbk | 19 ++++++++++++++++--- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/doc/boyer_moore.qbk b/doc/boyer_moore.qbk index 13c9666..1651133 100644 --- a/doc/boyer_moore.qbk +++ b/doc/boyer_moore.qbk @@ -37,7 +37,7 @@ public: ~boyer_moore (); template - corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last ); + pair operator () ( corpusIter corpus_first, corpusIter corpus_last ); }; `` @@ -45,14 +45,28 @@ and here is the corresponding procedural interface: `` template -corpusIter boyer_moore_search ( +pair boyer_moore_search ( corpusIter corpus_first, corpusIter corpus_last, patIter pat_first, patIter pat_last ); `` Each of the functions is passed two pairs of iterators. The first two define the corpus and the second two define the pattern. Note that the two pairs need not be of the same type, but they do need to "point" at the same type. In other words, `patIter::value_type` and `curpusIter::value_type` need to be the same type. -The return value of the function is an iterator pointing to the start of the pattern in the corpus. If the pattern is not found, it returns the end of the corpus (`corpus_last`). +The return value of the function is a pair of iterators pointing to the position of the pattern in the corpus. If the pattern is empty, it returns at empty range at the start of the corpus (`corpus_first`, `corpus_first`). If the pattern is not found, it returns at empty range at the end of the corpus (`corpus_last`, `corpus_last`). + +[heading Compatibility Note] + +Earlier versions of this searcher returned only a single iterator. As explained in [@https://cplusplusmusings.wordpress.com/2016/02/01/sometimes-you-get-things-wrong/], this was a suboptimal interface choice, and has been changed, starting in the 1.62.0 release. Old code that is expecting a single iterator return value can be updated by replacing the return value of the searcher's `operator ()` with the `.first` field of the pair. + +Instead of: +`` +iterator foo = searcher(a, b); +`` + +you now write: +`` +iterator foo = searcher(a, b).first; +`` [heading Performance] diff --git a/doc/boyer_moore_horspool.qbk b/doc/boyer_moore_horspool.qbk index 3a10c32..5b8491a 100644 --- a/doc/boyer_moore_horspool.qbk +++ b/doc/boyer_moore_horspool.qbk @@ -35,7 +35,7 @@ public: ~boyer_moore_horspool (); template - corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last ); + pair operator () ( corpusIter corpus_first, corpusIter corpus_last ); }; `` @@ -43,14 +43,28 @@ and here is the corresponding procedural interface: `` template -corpusIter boyer_moore_horspool_search ( +pair boyer_moore_horspool_search ( corpusIter corpus_first, corpusIter corpus_last, patIter pat_first, patIter pat_last ); `` Each of the functions is passed two pairs of iterators. The first two define the corpus and the second two define the pattern. Note that the two pairs need not be of the same type, but they do need to "point" at the same type. In other words, `patIter::value_type` and `curpusIter::value_type` need to be the same type. -The return value of the function is an iterator pointing to the start of the pattern in the corpus. If the pattern is not found, it returns the end of the corpus (`corpus_last`). +The return value of the function is a pair of iterators pointing to the position of the pattern in the corpus. If the pattern is empty, it returns at empty range at the start of the corpus (`corpus_first`, `corpus_first`). If the pattern is not found, it returns at empty range at the end of the corpus (`corpus_last`, `corpus_last`). + +[heading Compatibility Note] + +Earlier versions of this searcher returned only a single iterator. As explained in [@https://cplusplusmusings.wordpress.com/2016/02/01/sometimes-you-get-things-wrong/], this was a suboptimal interface choice, and has been changed, starting in the 1.62.0 release. Old code that is expecting a single iterator return value can be updated by replacing the return value of the searcher's `operator ()` with the `.first` field of the pair. + +Instead of: +`` +iterator foo = searcher(a, b); +`` + +you now write: +`` +iterator foo = searcher(a, b).first; +`` [heading Performance] diff --git a/doc/knuth_morris_pratt.qbk b/doc/knuth_morris_pratt.qbk index 7b184cf..b2620f1 100644 --- a/doc/knuth_morris_pratt.qbk +++ b/doc/knuth_morris_pratt.qbk @@ -39,7 +39,7 @@ public: ~knuth_morris_pratt (); template - corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last ); + pair operator () ( corpusIter corpus_first, corpusIter corpus_last ); }; `` @@ -47,15 +47,28 @@ and here is the corresponding procedural interface: `` template -corpusIter knuth_morris_pratt_search ( +pair knuth_morris_pratt_search ( corpusIter corpus_first, corpusIter corpus_last, patIter pat_first, patIter pat_last ); `` Each of the functions is passed two pairs of iterators. The first two define the corpus and the second two define the pattern. Note that the two pairs need not be of the same type, but they do need to "point" at the same type. In other words, `patIter::value_type` and `curpusIter::value_type` need to be the same type. -The return value of the function is an iterator pointing to the start of the pattern in the corpus. If the pattern is not found, it returns the end of the corpus (`corpus_last`). +The return value of the function is a pair of iterators pointing to the position of the pattern in the corpus. If the pattern is empty, it returns at empty range at the start of the corpus (`corpus_first`, `corpus_first`). If the pattern is not found, it returns at empty range at the end of the corpus (`corpus_last`, `corpus_last`). +[heading Compatibility Note] + +Earlier versions of this searcher returned only a single iterator. As explained in [@https://cplusplusmusings.wordpress.com/2016/02/01/sometimes-you-get-things-wrong/], this was a suboptimal interface choice, and has been changed, starting in the 1.62.0 release. Old code that is expecting a single iterator return value can be updated by replacing the return value of the searcher's `operator ()` with the `.first` field of the pair. + +Instead of: +`` +iterator foo = searcher(a, b); +`` + +you now write: +`` +iterator foo = searcher(a, b).first; +`` [heading Performance] The execution time of the Knuth-Morris-Pratt algorithm is linear in the size of the string being searched. Generally the algorithm gets faster as the pattern being searched for becomes longer. Its efficiency derives from the fact that with each unsuccessful attempt to find a match between the search string and the text it is searching, it uses the information gained from that attempt to rule out as many positions of the text as possible where the string cannot match. From 7977bd0cdc4dd62cd928ea60ce9b670ba815a08a Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 20 Nov 2016 17:02:49 -0800 Subject: [PATCH 05/16] Remove all mentions of (unary|binary)_function; not needed and they have been removed for C++17 --- include/boost/algorithm/cxx14/equal.hpp | 3 +-- include/boost/algorithm/string/detail/case_conv.hpp | 8 ++++++-- include/boost/algorithm/string/detail/util.hpp | 5 +++-- test/all_of_test.cpp | 2 +- test/any_of_test.cpp | 2 +- test/none_of_test.cpp | 2 +- test/one_of_test.cpp | 2 +- 7 files changed, 14 insertions(+), 10 deletions(-) diff --git a/include/boost/algorithm/cxx14/equal.hpp b/include/boost/algorithm/cxx14/equal.hpp index f1539f8..9f97be1 100644 --- a/include/boost/algorithm/cxx14/equal.hpp +++ b/include/boost/algorithm/cxx14/equal.hpp @@ -13,7 +13,6 @@ #define BOOST_ALGORITHM_EQUAL_HPP #include // for std::equal -#include // for std::binary_function #include namespace boost { namespace algorithm { @@ -21,7 +20,7 @@ namespace boost { namespace algorithm { namespace detail { template - struct eq : public std::binary_function { + struct eq { bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;} }; diff --git a/include/boost/algorithm/string/detail/case_conv.hpp b/include/boost/algorithm/string/detail/case_conv.hpp index 42621c7..233912c 100644 --- a/include/boost/algorithm/string/detail/case_conv.hpp +++ b/include/boost/algorithm/string/detail/case_conv.hpp @@ -30,8 +30,10 @@ namespace boost { // a tolower functor template - struct to_lowerF : public std::unary_function + struct to_lowerF { + typedef CharT argument_type; + typedef CharT result_type; // Constructor to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {} @@ -50,8 +52,10 @@ namespace boost { // a toupper functor template - struct to_upperF : public std::unary_function + struct to_upperF { + typedef CharT argument_type; + typedef CharT result_type; // Constructor to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {} diff --git a/include/boost/algorithm/string/detail/util.hpp b/include/boost/algorithm/string/detail/util.hpp index cf4a8b1..7844b67 100644 --- a/include/boost/algorithm/string/detail/util.hpp +++ b/include/boost/algorithm/string/detail/util.hpp @@ -89,9 +89,10 @@ namespace boost { template< typename SeqT, typename IteratorT=BOOST_STRING_TYPENAME SeqT::const_iterator > - struct copy_iterator_rangeF : - public std::unary_function< iterator_range, SeqT > + struct copy_iterator_rangeF { + typedef iterator_range argument_type; + typedef SeqT result_type; SeqT operator()( const iterator_range& Range ) const { return copy_range(Range); diff --git a/test/all_of_test.cpp b/test/all_of_test.cpp index 36918d5..b90eb27 100644 --- a/test/all_of_test.cpp +++ b/test/all_of_test.cpp @@ -18,7 +18,7 @@ #include template -struct is_ : public std::unary_function { +struct is_ { is_ ( T v ) : val_ ( v ) {} ~is_ () {} bool operator () ( T comp ) const { return val_ == comp; } diff --git a/test/any_of_test.cpp b/test/any_of_test.cpp index a3267c5..f576a3c 100644 --- a/test/any_of_test.cpp +++ b/test/any_of_test.cpp @@ -18,7 +18,7 @@ #include template -struct is_ : public std::unary_function { +struct is_ { is_ ( T v ) : val_ ( v ) {} ~is_ () {} bool operator () ( T comp ) const { return val_ == comp; } diff --git a/test/none_of_test.cpp b/test/none_of_test.cpp index fc74945..b9b40c6 100644 --- a/test/none_of_test.cpp +++ b/test/none_of_test.cpp @@ -18,7 +18,7 @@ #include template -struct is_ : public std::unary_function { +struct is_ { is_ ( T v ) : val_ ( v ) {} ~is_ () {} bool operator () ( T comp ) const { return val_ == comp; } diff --git a/test/one_of_test.cpp b/test/one_of_test.cpp index 9422881..ccc3a97 100644 --- a/test/one_of_test.cpp +++ b/test/one_of_test.cpp @@ -18,7 +18,7 @@ #include template -struct is_ : public std::unary_function { +struct is_ { is_ ( T v ) : val_ ( v ) {} ~is_ () {} bool operator () ( T comp ) const { return val_ == comp; } From 9b19fc00c22bad292977b3e85130974fb9812cdf Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 20 Nov 2016 17:24:19 -0800 Subject: [PATCH 06/16] use std::shuffle instead of random_shuffle in C++11 and later --- test/partition_subrange_test.cpp | 34 ++++++++++++++++++++++---------- test/sort_subrange_test.cpp | 34 ++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/test/partition_subrange_test.cpp b/test/partition_subrange_test.cpp index 018f140..c33fb46 100644 --- a/test/partition_subrange_test.cpp +++ b/test/partition_subrange_test.cpp @@ -7,6 +7,20 @@ #include #include + +#if __cplusplus >= 201103L +#include + +std::default_random_engine gen; +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::shuffle(first, last, gen); } +#else +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::random_shuffle(first, last); } +#endif + namespace ba = boost::algorithm; template @@ -72,14 +86,14 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[5], 5); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, b + 8); check_sequence (b, v.end(), b + 7, b + 8); // BOOST_CHECK_EQUAL(v[7], 7); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, v.end()); check_sequence (b, v.end(), b + 7, v.end()); @@ -88,7 +102,7 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[9], 9); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b + 2); check_sequence (b, v.end(), b, b + 2); @@ -96,12 +110,12 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[1], 1); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b); check_sequence (b, v.end(), b, b); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, v.end()); check_sequence (b, v.end(), b, v.end()); } @@ -120,14 +134,14 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[5], 4); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, b + 8, std::greater()); check_sequence (b, v.end(), b + 7, b + 8, std::greater()); // BOOST_CHECK_EQUAL(v[7], 2); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b + 7, v.end(), std::greater()); check_sequence (b, v.end(), b + 7, v.end(), std::greater()); @@ -136,7 +150,7 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[9], 0); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b + 2, std::greater()); check_sequence (b, v.end(), b, b + 2, std::greater()); @@ -144,12 +158,12 @@ BOOST_AUTO_TEST_CASE( test_main ) // BOOST_CHECK_EQUAL(v[1], 8); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, b, std::greater()); check_sequence (b, v.end(), b, b, std::greater()); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::partition_subrange(b, v.end(), b, v.end(), std::greater()); check_sequence (b, v.end(), b, v.end(), std::greater()); } diff --git a/test/sort_subrange_test.cpp b/test/sort_subrange_test.cpp index 4c1192e..de6a3fa 100644 --- a/test/sort_subrange_test.cpp +++ b/test/sort_subrange_test.cpp @@ -7,6 +7,20 @@ #include #include + +#if __cplusplus >= 201103L +#include + +std::default_random_engine gen; +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::shuffle(first, last, gen); } +#else +template +void do_shuffle(RandomIt first, RandomIt last) +{ std::random_shuffle(first, last); } +#endif + namespace ba = boost::algorithm; template @@ -53,14 +67,14 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[5], 5); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, b + 8); check_sequence (b, v.end(), b + 7, b + 8); BOOST_CHECK_EQUAL(v[7], 7); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, v.end()); check_sequence (b, v.end(), b + 7, v.end()); @@ -69,7 +83,7 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[9], 9); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b + 2); check_sequence (b, v.end(), b, b + 2); @@ -77,12 +91,12 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[1], 1); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b); check_sequence (b, v.end(), b, b); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, v.end()); check_sequence (b, v.end(), b, v.end()); } @@ -101,14 +115,14 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[5], 4); // Mix them up and try again - single element - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, b + 8, std::greater()); check_sequence (b, v.end(), b + 7, b + 8, std::greater()); BOOST_CHECK_EQUAL(v[7], 2); // Mix them up and try again - at the end - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b + 7, v.end(), std::greater()); check_sequence (b, v.end(), b + 7, v.end(), std::greater()); @@ -117,7 +131,7 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[9], 0); // Mix them up and try again - at the beginning - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b + 2, std::greater()); check_sequence (b, v.end(), b, b + 2, std::greater()); @@ -125,12 +139,12 @@ BOOST_AUTO_TEST_CASE( test_main ) BOOST_CHECK_EQUAL(v[1], 8); // Mix them up and try again - empty subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, b, std::greater()); check_sequence (b, v.end(), b, b, std::greater()); // Mix them up and try again - entire subrange - std::random_shuffle(v.begin(), v.end()); + do_shuffle(v.begin(), v.end()); ba::sort_subrange(b, v.end(), b, v.end(), std::greater()); check_sequence (b, v.end(), b, v.end(), std::greater()); } From 42db8a44037c8492d9c7a7e1a09b3c8831fdad23 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 25 Nov 2016 08:11:01 -0800 Subject: [PATCH 07/16] Change name of parameter; fixes 'shadowing' warning (Trac #12623) --- include/boost/algorithm/searching/boyer_moore.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/algorithm/searching/boyer_moore.hpp b/include/boost/algorithm/searching/boyer_moore.hpp index 65a809d..a72a40e 100644 --- a/include/boost/algorithm/searching/boyer_moore.hpp +++ b/include/boost/algorithm/searching/boyer_moore.hpp @@ -172,15 +172,15 @@ Requirements: } } - void build_suffix_table ( patIter pat_first, patIter pat_last ) { - const std::size_t count = (std::size_t) std::distance ( pat_first, pat_last ); + void build_suffix_table ( patIter first, patIter last ) { + const std::size_t count = (std::size_t) std::distance ( first, last ); if ( count > 0 ) { // empty pattern std::vector::value_type> reversed(count); - (void) std::reverse_copy ( pat_first, pat_last, reversed.begin ()); + (void) std::reverse_copy ( first, last, reversed.begin ()); std::vector prefix (count); - compute_bm_prefix ( pat_first, pat_last, prefix ); + compute_bm_prefix ( first, last, prefix ); std::vector prefix_reversed (count); compute_bm_prefix ( reversed.begin (), reversed.end (), prefix_reversed ); From e442420d496c7ae6424d418cb19520026537f0a5 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Fri, 25 Nov 2016 20:50:53 -0800 Subject: [PATCH 08/16] Change name of (another) parameter; fixes 'shadowing' warning (Trac #12623) --- include/boost/algorithm/searching/boyer_moore.hpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/algorithm/searching/boyer_moore.hpp b/include/boost/algorithm/searching/boyer_moore.hpp index a72a40e..192d4de 100644 --- a/include/boost/algorithm/searching/boyer_moore.hpp +++ b/include/boost/algorithm/searching/boyer_moore.hpp @@ -152,8 +152,8 @@ Requirements: template - void compute_bm_prefix ( Iter pat_first, Iter pat_last, Container &prefix ) { - const std::size_t count = std::distance ( pat_first, pat_last ); + void compute_bm_prefix ( Iter first, Iter last, Container &prefix ) { + const std::size_t count = std::distance ( first, last ); BOOST_ASSERT ( count > 0 ); BOOST_ASSERT ( prefix.size () == count ); @@ -161,12 +161,12 @@ Requirements: std::size_t k = 0; for ( std::size_t i = 1; i < count; ++i ) { BOOST_ASSERT ( k < count ); - while ( k > 0 && ( pat_first[k] != pat_first[i] )) { + while ( k > 0 && ( first[k] != first[i] )) { BOOST_ASSERT ( k < count ); k = prefix [ k - 1 ]; } - if ( pat_first[k] == pat_first[i] ) + if ( first[k] == first[i] ) k++; prefix [ i ] = k; } From 25d54bd1e8833666d9a7c2ecd4a5b576429afd78 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 13 Dec 2016 19:36:43 +0000 Subject: [PATCH 09/16] Build the algorithm documentation standalone. --- doc/Jamfile.v2 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/Jamfile.v2 b/doc/Jamfile.v2 index ef482ec..360b973 100644 --- a/doc/Jamfile.v2 +++ b/doc/Jamfile.v2 @@ -47,10 +47,10 @@ boostbook standalone ############################################################################### alias boostdoc - : algorithm ../string/doc/string_algo.xml + : ../string/doc/string_algo.xml : - : autodoc ../string/doc//autodoc + : ../string/doc//autodoc : ; explicit boostdoc ; -alias boostrelease ; +alias boostrelease : standalone ; explicit boostrelease ; From d22c60c2d4c1e5b3e29f978fba59aa53fdcd07bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Hunold?= Date: Fri, 6 Jan 2017 09:59:12 +0100 Subject: [PATCH 10/16] Remove trailing ";" clang warning: extra ';' after member function definition [-Wextra-semi] --- include/boost/algorithm/string/detail/find_iterator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/algorithm/string/detail/find_iterator.hpp b/include/boost/algorithm/string/detail/find_iterator.hpp index 9b78a0f..4f90a98 100644 --- a/include/boost/algorithm/string/detail/find_iterator.hpp +++ b/include/boost/algorithm/string/detail/find_iterator.hpp @@ -40,7 +40,7 @@ namespace boost { // Protected construction/destruction // Default constructor - find_iterator_base() {}; + find_iterator_base() {} // Copy construction find_iterator_base( const find_iterator_base& Other ) : m_Finder(Other.m_Finder) {} From a838feb81ad02dabe3e619987990d19fc6bbbcf9 Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Tue, 14 Feb 2017 12:22:49 +0300 Subject: [PATCH 11/16] Added is_partitioned_until * Fixed doxygen comment in is_partitioned algorithm. --- .../boost/algorithm/cxx11/is_partitioned.hpp | 2 +- .../boost/algorithm/is_partitioned_until.hpp | 61 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 include/boost/algorithm/is_partitioned_until.hpp diff --git a/include/boost/algorithm/cxx11/is_partitioned.hpp b/include/boost/algorithm/cxx11/is_partitioned.hpp index cb6c71e..80ee577 100644 --- a/include/boost/algorithm/cxx11/is_partitioned.hpp +++ b/include/boost/algorithm/cxx11/is_partitioned.hpp @@ -39,7 +39,7 @@ bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p } /// \fn is_partitioned ( const Range &r, UnaryPredicate p ) -/// \brief Generates an increasing sequence of values, and stores them in the input Range. +/// \brief Tests to see if a sequence is partitioned according to a predicate /// /// \param r The input range /// \param p The predicate to test the values with diff --git a/include/boost/algorithm/is_partitioned_until.hpp b/include/boost/algorithm/is_partitioned_until.hpp new file mode 100644 index 0000000..e188927 --- /dev/null +++ b/include/boost/algorithm/is_partitioned_until.hpp @@ -0,0 +1,61 @@ +/* + Copyright (c) Alexander Zaitsev 2017. + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +*/ + +/// \file is_partitioned_until.hpp +/// \brief Tell if a sequence is partitioned +/// \author Alexander Zaitsev + +#ifndef BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP +#define BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP + +#include +#include + +namespace boost { namespace algorithm { + +/// \fn is_partitioned_until ( InputIterator first, InputIterator last, UnaryPredicate p ) +/// \brief Tests to see if a sequence is partitioned according to a predicate +/// +/// \param first The start of the input sequence +/// \param last One past the end of the input sequence +/// \param p The predicate to test the values with +/// +/// \note Returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. +/// Returns last if the entire sequence is partitioned. +/// Complexity: O(N). +template +InputIterator is_partitioned_until ( InputIterator first, InputIterator last, UnaryPredicate p ) +{ +// Run through the part that satisfy the predicate + for ( ; first != last; ++first ) + if ( !p (*first)) + break; +// Now the part that does not satisfy the predicate + for ( ; first != last; ++first ) + if ( p (*first)) + return first; + return last; +} + +/// \fn is_partitioned_until ( const Range &r, UnaryPredicate p ) +/// \brief Tests to see if a sequence is partitioned according to a predicate +/// +/// \param r The input range +/// \param p The predicate to test the values with +/// +/// \note Returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. +/// Returns last if the entire sequence is partitioned. +/// Complexity: O(N). +template +typename boost::range_iterator::type is_partitioned_until ( const Range &r, UnaryPredicate p ) +{ + return boost::algorithm::is_partitioned_until (boost::begin(r), boost::end(r), p); +} + +}} + +#endif // BOOST_ALGORITHM_IS_PARTITIONED_UNTIL_HPP From 383e800df9cf59b8cdcdb3c40a11d5981cf2b7ba Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Tue, 14 Feb 2017 15:59:07 +0300 Subject: [PATCH 12/16] Added examples, tests, doc --- doc/algorithm.qbk | 1 + doc/is_partitioned_until.qbk | 67 ++++++++++++++++++ example/Jamfile.v2 | 1 + example/is_partitioned_until_example.cpp | 70 +++++++++++++++++++ .../boost/algorithm/is_partitioned_until.hpp | 4 +- test/Jamfile.v2 | 3 + test/is_partitioned_until_test.cpp | 63 +++++++++++++++++ 7 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 doc/is_partitioned_until.qbk create mode 100644 example/is_partitioned_until_example.cpp create mode 100644 test/is_partitioned_until_test.cpp diff --git a/doc/algorithm.qbk b/doc/algorithm.qbk index 1568fb5..becad46 100644 --- a/doc/algorithm.qbk +++ b/doc/algorithm.qbk @@ -67,6 +67,7 @@ Thanks to all the people who have reviewed this library and made suggestions for [include gather.qbk] [include hex.qbk] [include is_palindrome.qbk] +[include is_partitioned_until.qbk] [endsect] diff --git a/doc/is_partitioned_until.qbk b/doc/is_partitioned_until.qbk new file mode 100644 index 0000000..72e2afc --- /dev/null +++ b/doc/is_partitioned_until.qbk @@ -0,0 +1,67 @@ +[/ File is_partitioned_until.qbk] + +[section:is_partitioned_until is_partitioned_until ] + +[/license +Copyright (c) 2017 Alexander Zaitsev + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +] + +The header file 'is_partitioned_until.hpp' contains two variants of a single algorithm, `is_partitioned_until`. The algorithm tests to see if a sequence is partitioned according to a predicate; in other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. + +The routine `is_partitioned_until` takes a sequence and a predicate. It returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. Returns last if the entire sequence is partitioned. + +`is_partitioned_until` come in two forms; the first one takes two iterators to define the range. The second form takes a single range parameter, and uses Boost.Range to traverse it. + + +[heading interface] + +The function `is_partitioned_until` returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. Returns last if the entire sequence is partitioned. There are two versions; one takes two iterators, and the other takes a range. + +`` +template + InputIterator is_partitioned_until ( InputIterator first, InputIterator last, Predicate p ); +template + typename boost::range_iterator::type is_partitioned_until ( const Range &r, Predicate p ); +`` + +[heading Examples] + +Given the container `c` containing `{ 0, 1, 2, 3, 14, 15 }`, then +`` +bool isOdd ( int i ) { return i % 2 == 1; } +bool lessThan10 ( int i ) { return i < 10; } + +is_partitioned_until ( c, isOdd ) --> iterator to '1' +is_partitioned_until ( c, lessThan10 ) --> end +is_partitioned_until ( c.begin (), c.end (), lessThan10 ) --> end +is_partitioned_until ( c.begin (), c.begin () + 3, lessThan10 ) --> end +is_partitioned_until ( c.end (), c.end (), isOdd ) --> end // empty range +`` + +[heading Iterator Requirements] + +`is_partitioned_until` works on all iterators except output iterators. + +[heading Complexity] + +Both of the variants of `is_partitioned_until` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If the sequence is found to be not partitioned at any point, the routine will terminate immediately, without examining the rest of the elements. + +[heading Exception Safety] + +Both of the variants of `is_partitioned_until` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. + +[heading Notes] + +* `is_partitioned_until` returns iterator to the end for empty ranges, no matter what predicate is passed to test against. + +[endsect] + +[/ File is_partitioned_until.qbk +Copyright 2017 Alexander Zaitsev +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). +] + diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index ce067cf..4512a53 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -21,4 +21,5 @@ project /boost/algorithm/example exe clamp_example : clamp_example.cpp ; exe search_example : search_example.cpp ; exe is_palindrome_example : is_palindrome_example.cpp; +exe is_partitioned_until_example : is_partitioned_until_example.cpp; diff --git a/example/is_partitioned_until_example.cpp b/example/is_partitioned_until_example.cpp new file mode 100644 index 0000000..759176b --- /dev/null +++ b/example/is_partitioned_until_example.cpp @@ -0,0 +1,70 @@ +/* + Copyright (c) Alexander Zaitsev , 2017 + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + For more information, see http://www.boost.org +*/ + +#include +#include +#include + +#include + + +namespace ba = boost::algorithm; + +bool isOdd(const int v1) +{ + return v1 % 2 != 0; +} + +struct isOddComp +{ + bool operator()(const int v1) const + { + return v1 % 2 != 0; + } +}; + + +int main ( int /*argc*/, char * /*argv*/ [] ) +{ + std::vector good({1, 2, 4}); + std::vector bad({1, 2, 3}); + + //Use custom function + auto it1 = ba::is_partitioned_until(good.begin(), good.end(), isOdd); + if(it1 == good.end()) + { + std::cout << "The sequence is partitioned\n"; + } + else + { + std::cout << "is_partitioned_until check failed here: " << *it1 << std::endl; + } + + //Use custom comparator + auto it2 = ba::is_partitioned_until(good.begin(), good.end(), isOddComp()); + if(it2 == good.end()) + { + std::cout << "The sequence is partitioned\n"; + } + else + { + std::cout << "is_partitioned_until check failed here: " << *it2 << std::endl; + } + + auto it3 = ba::is_partitioned_until(bad, isOdd); + if(it3 == bad.end()) + { + std::cout << "The sequence is partitioned\n"; + } + else + { + std::cout << "is_partitioned_until check failed here: " << *it3 << std::endl; + } + return 0; +} diff --git a/include/boost/algorithm/is_partitioned_until.hpp b/include/boost/algorithm/is_partitioned_until.hpp index e188927..99e8435 100644 --- a/include/boost/algorithm/is_partitioned_until.hpp +++ b/include/boost/algorithm/is_partitioned_until.hpp @@ -1,5 +1,5 @@ /* - Copyright (c) Alexander Zaitsev 2017. + Copyright (c) Alexander Zaitsev , 2017. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -51,7 +51,7 @@ InputIterator is_partitioned_until ( InputIterator first, InputIterator last, Un /// Returns last if the entire sequence is partitioned. /// Complexity: O(N). template -typename boost::range_iterator::type is_partitioned_until ( const Range &r, UnaryPredicate p ) +typename boost::range_iterator::type is_partitioned_until ( const Range &r, UnaryPredicate p ) { return boost::algorithm::is_partitioned_until (boost::begin(r), boost::end(r), p); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index fb00843..fad1578 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -70,6 +70,9 @@ alias unit_test_framework # Is_palindrome tests [ run is_palindrome_test.cpp unit_test_framework : : : : is_palindrome_test ] + +# Is_partitioned_until tests + [ run is_partitioned_until_test.cpp unit_test_framework : : : : is_partitioned_until_test ] ; } diff --git a/test/is_partitioned_until_test.cpp b/test/is_partitioned_until_test.cpp new file mode 100644 index 0000000..379c06e --- /dev/null +++ b/test/is_partitioned_until_test.cpp @@ -0,0 +1,63 @@ +/* + Copyright (c) Marshall Clow 2011-2012, Alexander Zaitsev , 2017. + + Distributed under the Boost Software License, Version 1.0. (See accompanying + file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + + For more information, see http://www.boost.org +*/ + +#include + +#include +#include + +#define BOOST_TEST_MAIN +#include + +#include +#include +#include + +namespace ba = boost::algorithm; +// namespace ba = boost; + +template +struct less_than { +public: + less_than ( T foo ) : val ( foo ) {} + less_than ( const less_than &rhs ) : val ( rhs.val ) {} + + bool operator () ( const T &v ) const { return v < val; } +private: + less_than (); + less_than operator = ( const less_than &rhs ); + T val; +}; + + +void test_sequence1 () { + std::vector v; + + v.clear (); + for ( int i = 5; i < 15; ++i ) + v.push_back ( i ); + BOOST_CHECK ( ba::is_partitioned_until ( v, less_than(3)) == v.end()); // no elements + BOOST_CHECK ( ba::is_partitioned_until ( v, less_than(6)) == v.end()); // only the first element + BOOST_CHECK ( ba::is_partitioned_until ( v, less_than(10)) == v.end()); // in the middle somewhere + BOOST_CHECK ( ba::is_partitioned_until ( v, less_than(99)) == v.end()); // all elements satisfy +// With bidirectional iterators. + std::list l; + for ( int i = 5; i < 15; ++i ) + l.push_back ( i ); + BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than(3)) == l.end()); // no elements + BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than(6)) == l.end()); // only the first element + BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than(10)) == l.end()); // in the middle somewhere + BOOST_CHECK ( ba::is_partitioned_until ( l.begin (), l.end (), less_than(99)) == l.end()); // all elements satisfy +} + + +BOOST_AUTO_TEST_CASE( test_main ) +{ + test_sequence1 (); +} From a446ef0758017ab090630f562bd32e2c21c57941 Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 15 Feb 2017 00:11:10 +0300 Subject: [PATCH 13/16] Cleaned README --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 92a9140..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,4 +1 @@ - - Coverity Scan Build Status - + From 6f341453904a46e9cb70256d815307aaa73d4aa5 Mon Sep 17 00:00:00 2001 From: Alexander Zaitsev Date: Wed, 22 Feb 2017 01:25:38 +0300 Subject: [PATCH 14/16] Removed empty README.md, fixed docs --- README.md | 4 ---- doc/is_partitioned.qbk | 2 +- doc/is_partitioned_until.qbk | 6 +++--- include/boost/algorithm/cxx11/is_partitioned.hpp | 6 ++++-- include/boost/algorithm/is_partitioned_until.hpp | 6 ++++-- 5 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index 92a9140..0000000 --- a/README.md +++ /dev/null @@ -1,4 +0,0 @@ - - Coverity Scan Build Status - diff --git a/doc/is_partitioned.qbk b/doc/is_partitioned.qbk index 7a6c458..0ed1f80 100644 --- a/doc/is_partitioned.qbk +++ b/doc/is_partitioned.qbk @@ -57,7 +57,7 @@ Both of the variants of `is_partitioned` take their parameters by value or const * The iterator-based version of the routine `is_partitioned` is also available as part of the C++11 standard. -* `is_partitioned` returns true for empty ranges, no matter what predicate is passed to test against. +* `is_partitioned` returns true for empty and single-element ranges, no matter what predicate is passed to test against. [endsect] diff --git a/doc/is_partitioned_until.qbk b/doc/is_partitioned_until.qbk index 72e2afc..9e0879b 100644 --- a/doc/is_partitioned_until.qbk +++ b/doc/is_partitioned_until.qbk @@ -11,14 +11,14 @@ Distributed under the Boost Software License, Version 1.0. The header file 'is_partitioned_until.hpp' contains two variants of a single algorithm, `is_partitioned_until`. The algorithm tests to see if a sequence is partitioned according to a predicate; in other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. -The routine `is_partitioned_until` takes a sequence and a predicate. It returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. Returns last if the entire sequence is partitioned. +The routine `is_partitioned_until` takes a sequence and a predicate. It returns the last iterator 'it' in the sequence [begin, end) for which the is_partitioned(begin, it) is true. `is_partitioned_until` come in two forms; the first one takes two iterators to define the range. The second form takes a single range parameter, and uses Boost.Range to traverse it. [heading interface] -The function `is_partitioned_until` returns the first iterator 'it' in the sequence [first, last) for which is_partitioned(first, it, p) is false. Returns last if the entire sequence is partitioned. There are two versions; one takes two iterators, and the other takes a range. +The function `is_partitioned_until` returns the last iterator 'it' in the sequence [begin, end) for which the is_partitioned(begin, it) is true. There are two versions; one takes two iterators, and the other takes a range. `` template @@ -55,7 +55,7 @@ Both of the variants of `is_partitioned_until` take their parameters by value or [heading Notes] -* `is_partitioned_until` returns iterator to the end for empty ranges, no matter what predicate is passed to test against. +* `is_partitioned_until` returns iterator to the end for empty and single-element ranges, no matter what predicate is passed to test against. [endsect] diff --git a/include/boost/algorithm/cxx11/is_partitioned.hpp b/include/boost/algorithm/cxx11/is_partitioned.hpp index 80ee577..c0076b9 100644 --- a/include/boost/algorithm/cxx11/is_partitioned.hpp +++ b/include/boost/algorithm/cxx11/is_partitioned.hpp @@ -18,7 +18,8 @@ namespace boost { namespace algorithm { /// \fn is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p ) -/// \brief Tests to see if a sequence is partitioned according to a predicate +/// \brief Tests to see if a sequence is partitioned according to a predicate. +/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. /// /// \param first The start of the input sequence /// \param last One past the end of the input sequence @@ -39,7 +40,8 @@ bool is_partitioned ( InputIterator first, InputIterator last, UnaryPredicate p } /// \fn is_partitioned ( const Range &r, UnaryPredicate p ) -/// \brief Tests to see if a sequence is partitioned according to a predicate +/// \brief Tests to see if a sequence is partitioned according to a predicate. +/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. /// /// \param r The input range /// \param p The predicate to test the values with diff --git a/include/boost/algorithm/is_partitioned_until.hpp b/include/boost/algorithm/is_partitioned_until.hpp index 99e8435..42683e1 100644 --- a/include/boost/algorithm/is_partitioned_until.hpp +++ b/include/boost/algorithm/is_partitioned_until.hpp @@ -18,7 +18,8 @@ namespace boost { namespace algorithm { /// \fn is_partitioned_until ( InputIterator first, InputIterator last, UnaryPredicate p ) -/// \brief Tests to see if a sequence is partitioned according to a predicate +/// \brief Tests to see if a sequence is partitioned according to a predicate. +/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. /// /// \param first The start of the input sequence /// \param last One past the end of the input sequence @@ -42,7 +43,8 @@ InputIterator is_partitioned_until ( InputIterator first, InputIterator last, Un } /// \fn is_partitioned_until ( const Range &r, UnaryPredicate p ) -/// \brief Tests to see if a sequence is partitioned according to a predicate +/// \brief Tests to see if a sequence is partitioned according to a predicate. +/// In other words, all the items in the sequence that satisfy the predicate are at the beginning of the sequence. /// /// \param r The input range /// \param p The predicate to test the values with From 56d88410c66cdbe362b1084284da47aa5077a71d Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Sun, 1 Feb 2015 07:17:45 +0100 Subject: [PATCH 15/16] fix narrowing conversions Signed-off-by: Daniela Engert --- include/boost/algorithm/hex.hpp | 2 +- include/boost/algorithm/searching/knuth_morris_pratt.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/boost/algorithm/hex.hpp b/include/boost/algorithm/hex.hpp index 739e89f..b833584 100644 --- a/include/boost/algorithm/hex.hpp +++ b/include/boost/algorithm/hex.hpp @@ -73,7 +73,7 @@ namespace detail { else if ( c >= 'A' && c <= 'F' ) retval = c - 'A' + 10; else if ( c >= 'a' && c <= 'f' ) retval = c - 'a' + 10; else BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c)); - return retval; + return static_cast(retval); } // My own iterator_traits class. diff --git a/include/boost/algorithm/searching/knuth_morris_pratt.hpp b/include/boost/algorithm/searching/knuth_morris_pratt.hpp index c890c9c..5b5b64a 100644 --- a/include/boost/algorithm/searching/knuth_morris_pratt.hpp +++ b/include/boost/algorithm/searching/knuth_morris_pratt.hpp @@ -155,9 +155,9 @@ namespace boost { namespace algorithm { void preKmp ( patIter first, patIter last ) { - const /*std::size_t*/ int count = std::distance ( first, last ); + const difference_type count = std::distance ( first, last ); - int i, j; + difference_type i, j; i = 0; j = skip_[0] = -1; @@ -177,7 +177,7 @@ namespace boost { namespace algorithm { void init_skip_table ( patIter first, patIter last ) { const difference_type count = std::distance ( first, last ); - int j; + difference_type j; skip_ [ 0 ] = -1; for ( int i = 1; i <= count; ++i ) { j = skip_ [ i - 1 ]; From d6b7f3da904e0d8eb1dcec356d85a259aa4ff18b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 3 May 2017 22:38:21 -0700 Subject: [PATCH 16/16] Use boost::begin/end instead of macros --- test/is_palindrome_test.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/test/is_palindrome_test.cpp b/test/is_palindrome_test.cpp index c668e9d..ea2bb26 100644 --- a/test/is_palindrome_test.cpp +++ b/test/is_palindrome_test.cpp @@ -38,9 +38,6 @@ struct functorComparator } }; -#define Begin(arr) (arr) -#define End(arr) (arr+(sizeof(arr)/(sizeof(arr[0])))) - void test_is_palindrome() { const std::list empty; @@ -54,14 +51,14 @@ void test_is_palindrome() // Test a default operator== BOOST_CHECK ( ba::is_palindrome(empty)); BOOST_CHECK ( ba::is_palindrome(singleElement)); - BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome))); - BOOST_CHECK ( ba::is_palindrome(Begin(oddPalindrome), End(oddPalindrome))); - BOOST_CHECK ( ba::is_palindrome(Begin(evenPalindrome), End(evenPalindrome))); - BOOST_CHECK (!ba::is_palindrome(Begin(evenNonPalindrome), End(evenNonPalindrome))); + BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome))); + BOOST_CHECK ( ba::is_palindrome(boost::begin(oddPalindrome), boost::end(oddPalindrome))); + BOOST_CHECK ( ba::is_palindrome(boost::begin(evenPalindrome), boost::end(evenPalindrome))); + BOOST_CHECK (!ba::is_palindrome(boost::begin(evenNonPalindrome), boost::end(evenNonPalindrome))); //Test the custom comparators BOOST_CHECK ( ba::is_palindrome(empty.begin(), empty.end(), functorComparator())); - BOOST_CHECK (!ba::is_palindrome(Begin(oddNonPalindrome), End(oddNonPalindrome), funcComparator)); + BOOST_CHECK (!ba::is_palindrome(boost::begin(oddNonPalindrome), boost::end(oddNonPalindrome), funcComparator)); BOOST_CHECK ( ba::is_palindrome(evenPalindrome, std::equal_to())); //Test C-strings like cases