From 29bd9f53d958b987c5ab54dec9adeec43046367e Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 23 Sep 2012 14:56:41 +0000 Subject: [PATCH] Merge bug fixes to release; Fixes #7399 Fixes #7400 Fixes #7401 [SVN r80670] --- include/boost/algorithm/cxx11/copy_if.hpp | 6 +- .../boost/algorithm/cxx11/is_permutation.hpp | 8 +- .../searching/boyer_moore_horspool.hpp | 5 ++ .../searching/knuth_morris_pratt.hpp | 5 ++ test/Jamfile.v2 | 1 + test/copy_if_test1.cpp | 87 +++++++++++++++++++ 6 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 test/copy_if_test1.cpp diff --git a/include/boost/algorithm/cxx11/copy_if.hpp b/include/boost/algorithm/cxx11/copy_if.hpp index 6d0ba00..8591cb5 100644 --- a/include/boost/algorithm/cxx11/copy_if.hpp +++ b/include/boost/algorithm/cxx11/copy_if.hpp @@ -39,7 +39,7 @@ OutputIterator copy_if ( InputIterator first, InputIterator last, OutputIterator { for ( ; first != last; ++first ) if (p(*first)) - *result++ = first; + *result++ = *first; return result; } #endif @@ -75,7 +75,7 @@ OutputIterator copy_while ( InputIterator first, InputIterator last, OutputIterator result, Predicate p ) { for ( ; first != last && p(*first); ++first ) - *result++ = first; + *result++ = *first; return result; } @@ -109,7 +109,7 @@ template OutputIterator copy_until ( InputIterator first, InputIterator last, OutputIterator result, Predicate p ) { for ( ; first != last && !p(*first); ++first ) - *result++ = first; + *result++ = *first; return result; } diff --git a/include/boost/algorithm/cxx11/is_permutation.hpp b/include/boost/algorithm/cxx11/is_permutation.hpp index 33cb712..526ca2e 100644 --- a/include/boost/algorithm/cxx11/is_permutation.hpp +++ b/include/boost/algorithm/cxx11/is_permutation.hpp @@ -46,7 +46,7 @@ namespace detail { /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2, BinaryPredicate p ) -/// \brief Tests to see if a the sequence [first,last) is a permutation of the sequence starting at first2 +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param first The start of the input sequence /// \param last One past the end of the input sequence @@ -88,7 +88,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, } /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 first2 ) -/// \brief Tests to see if a the sequence [first,last) is a permutation of the sequence starting at first2 +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param first The start of the input sequence /// \param last One past the end of the input sequence @@ -108,7 +108,7 @@ bool is_permutation ( ForwardIterator1 first, ForwardIterator1 last, ForwardIter #endif /// \fn is_permutation ( const Range &r, ForwardIterator first2 ) -/// \brief Tests to see if a the sequence [first,last) is a permutation of the sequence starting at first2 +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param r The input range /// \param first2 The start of the second sequence @@ -119,7 +119,7 @@ bool is_permutation ( const Range &r, ForwardIterator first2 ) } /// \fn is_permutation ( const Range &r, ForwardIterator first2, BinaryPredicate pred ) -/// \brief Tests to see if a the sequence [first,last) is a permutation of the sequence starting at first2 +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 /// /// \param r The input range /// \param first2 The start of the second sequence diff --git a/include/boost/algorithm/searching/boyer_moore_horspool.hpp b/include/boost/algorithm/searching/boyer_moore_horspool.hpp index 5e59cf3..758ded2 100644 --- a/include/boost/algorithm/searching/boyer_moore_horspool.hpp +++ b/include/boost/algorithm/searching/boyer_moore_horspool.hpp @@ -14,6 +14,11 @@ #include #include + +#include +#include + +#include #include #include diff --git a/include/boost/algorithm/searching/knuth_morris_pratt.hpp b/include/boost/algorithm/searching/knuth_morris_pratt.hpp index cc83185..aaeeb51 100644 --- a/include/boost/algorithm/searching/knuth_morris_pratt.hpp +++ b/include/boost/algorithm/searching/knuth_morris_pratt.hpp @@ -15,6 +15,11 @@ #include #include + +#include +#include + +#include #include #include diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b9cfa2a..9db1cce 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -32,6 +32,7 @@ import testing ; [ run ordered_test.cpp : : : : ordered_test ] [ run find_if_not_test1.cpp : : : : find_if_not_test1 ] + [ run copy_if_test1.cpp : : : : copy_if_test1 ] [ run copy_n_test1.cpp : : : : copy_n_test1 ] [ run iota_test1.cpp : : : : iota_test1 ] diff --git a/test/copy_if_test1.cpp b/test/copy_if_test1.cpp new file mode 100644 index 0000000..cc3c7ae --- /dev/null +++ b/test/copy_if_test1.cpp @@ -0,0 +1,87 @@ +/* + Copyright (c) Marshall Clow 2012. + + 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 +#include +#include +#include +#include + +#include + +namespace ba = boost::algorithm; +// namespace ba = boost; + +bool is_true ( int v ) { return true; } +bool is_false ( int v ) { return false; } +bool is_even ( int v ) { return v % 2 == 0; } +bool is_odd ( int v ) { return v % 2 == 1; } + +template +void test_sequence ( Container const &c ) { + + typedef typename Container::value_type value_type; + std::vector v; + +// None of the elements + v.clear (); + ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_false); + BOOST_CHECK ( v.size () == 0 ); + + v.clear (); + ba::copy_if ( c, back_inserter ( v ), is_false); + BOOST_CHECK ( v.size () == 0 ); + +// All the elements + v.clear (); + ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_true); + BOOST_CHECK ( v.size () == c.size ()); + BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ())); + + v.clear (); + ba::copy_if ( c, back_inserter ( v ), is_true); + BOOST_CHECK ( v.size () == c.size ()); + BOOST_CHECK ( v.size () == c.size ()); + BOOST_CHECK ( std::equal ( c.begin (), c.end (), v.begin ())); + +// Some of the elements + v.clear (); + ba::copy_if ( c.begin (), c.end (), back_inserter ( v ), is_even ); + BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even )); + BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even )); + + v.clear (); + ba::copy_if ( c, back_inserter ( v ), is_even ); + BOOST_CHECK ( v.size () == std::count_if ( c.begin (), c.end (), is_even )); + BOOST_CHECK ( ba::all_of ( v.begin (), v.end (), is_even )); + } + + +void test_sequence1 () { + std::vector v; + for ( int i = 5; i < 15; ++i ) + v.push_back ( i ); + test_sequence ( v ); + + std::list l; + for ( int i = 25; i > 15; --i ) + l.push_back ( i ); + test_sequence ( l ); + } + + +int test_main( int , char* [] ) +{ + test_sequence1 (); + return 0; +}