From 747722a8dafaa5604b922ba79989fd318a2d0e1c Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Thu, 7 Nov 2013 21:31:06 +0000 Subject: [PATCH 1/6] Fix an uninitialized member in a default-initialized split_iterator; Refs #9335 [SVN r86583] --- include/boost/algorithm/string/find_iterator.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/algorithm/string/find_iterator.hpp b/include/boost/algorithm/string/find_iterator.hpp index 1502c7d..5834407 100644 --- a/include/boost/algorithm/string/find_iterator.hpp +++ b/include/boost/algorithm/string/find_iterator.hpp @@ -230,7 +230,7 @@ namespace boost { \post eof()==true */ - split_iterator() {} + split_iterator() { m_bEof = true; } //! Copy constructor /*! Construct a copy of the split_iterator From 0ac413ecb80ede820fef13563f97f55bc6126e85 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 17 Nov 2013 20:47:14 +0000 Subject: [PATCH 2/6] Updated docs for is_sorted, etc. Refs #9367 [SVN r86741] --- doc/ordered-hpp.qbk | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/doc/ordered-hpp.qbk b/doc/ordered-hpp.qbk index 718f1f9..9e860d4 100644 --- a/doc/ordered-hpp.qbk +++ b/doc/ordered-hpp.qbk @@ -19,11 +19,11 @@ The function `is_sorted(sequence)` determines whether or not a sequence is compl `` namespace boost { namespace algorithm { - template - bool is_sorted ( Iterator first, Iterator last, Pred p ); + template + bool is_sorted ( ForwardIterator first, ForwardIterator last, Pred p ); - template - bool is_sorted ( Iterator first, Iterator last ); + template + bool is_sorted ( ForwardIterator first, ForwardIterator last ); template @@ -34,7 +34,7 @@ namespace boost { namespace algorithm { }} `` -Iterator requirements: The `is_sorted` functions will work on all kinds of iterators (except output iterators). +Iterator requirements: The `is_sorted` functions will work forward iterators or better. [heading is_sorted_until] @@ -88,8 +88,8 @@ To test if a sequence is decreasing (each element no larger than the preceding o `` namespace boost { namespace algorithm { - template - bool is_decreasing ( Iterator first, Iterator last ); + template + bool is_decreasing ( ForwardIterator first, ForwardIterator last ); template bool is_decreasing ( const R &range ); @@ -99,8 +99,8 @@ namespace boost { namespace algorithm { To test if a sequence is strictly increasing (each element larger than the preceding one): `` namespace boost { namespace algorithm { - template - bool is_strictly_increasing ( Iterator first, Iterator last ); + template + bool is_strictly_increasing ( ForwardIterator first, ForwardIterator last ); template bool is_strictly_increasing ( const R &range ); @@ -110,8 +110,8 @@ namespace boost { namespace algorithm { To test if a sequence is strictly decreasing (each element smaller than the preceding one): `` namespace boost { namespace algorithm { - template - bool is_strictly_decreasing ( Iterator first, Iterator last ); + template + bool is_strictly_decreasing ( ForwardIterator first, ForwardIterator last ); template bool is_strictly_decreasing ( const R &range ); From bc3b806f5617c88e022096685a24b25bf39c82f1 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 4 Feb 2014 08:13:44 -0800 Subject: [PATCH 3/6] Fixed some file perms that got munged in the git conversion. --- include/boost/algorithm/clamp.hpp | 0 include/boost/algorithm/searching/boyer_moore.hpp | 0 include/boost/algorithm/searching/boyer_moore_horspool.hpp | 0 include/boost/algorithm/searching/detail/bm_traits.hpp | 0 include/boost/algorithm/searching/detail/debugging.hpp | 0 include/boost/algorithm/searching/knuth_morris_pratt.hpp | 0 test/Jamfile.v2 | 0 test/clamp_test.cpp | 0 test/empty_search_test.cpp | 0 test/search_test1.cpp | 0 test/search_test2.cpp | 0 test/search_test3.cpp | 0 12 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 include/boost/algorithm/clamp.hpp mode change 100755 => 100644 include/boost/algorithm/searching/boyer_moore.hpp mode change 100755 => 100644 include/boost/algorithm/searching/boyer_moore_horspool.hpp mode change 100755 => 100644 include/boost/algorithm/searching/detail/bm_traits.hpp mode change 100755 => 100644 include/boost/algorithm/searching/detail/debugging.hpp mode change 100755 => 100644 include/boost/algorithm/searching/knuth_morris_pratt.hpp mode change 100755 => 100644 test/Jamfile.v2 mode change 100755 => 100644 test/clamp_test.cpp mode change 100755 => 100644 test/empty_search_test.cpp mode change 100755 => 100644 test/search_test1.cpp mode change 100755 => 100644 test/search_test2.cpp mode change 100755 => 100644 test/search_test3.cpp diff --git a/include/boost/algorithm/clamp.hpp b/include/boost/algorithm/clamp.hpp old mode 100755 new mode 100644 diff --git a/include/boost/algorithm/searching/boyer_moore.hpp b/include/boost/algorithm/searching/boyer_moore.hpp old mode 100755 new mode 100644 diff --git a/include/boost/algorithm/searching/boyer_moore_horspool.hpp b/include/boost/algorithm/searching/boyer_moore_horspool.hpp old mode 100755 new mode 100644 diff --git a/include/boost/algorithm/searching/detail/bm_traits.hpp b/include/boost/algorithm/searching/detail/bm_traits.hpp old mode 100755 new mode 100644 diff --git a/include/boost/algorithm/searching/detail/debugging.hpp b/include/boost/algorithm/searching/detail/debugging.hpp old mode 100755 new mode 100644 diff --git a/include/boost/algorithm/searching/knuth_morris_pratt.hpp b/include/boost/algorithm/searching/knuth_morris_pratt.hpp old mode 100755 new mode 100644 diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 old mode 100755 new mode 100644 diff --git a/test/clamp_test.cpp b/test/clamp_test.cpp old mode 100755 new mode 100644 diff --git a/test/empty_search_test.cpp b/test/empty_search_test.cpp old mode 100755 new mode 100644 diff --git a/test/search_test1.cpp b/test/search_test1.cpp old mode 100755 new mode 100644 diff --git a/test/search_test2.cpp b/test/search_test2.cpp old mode 100755 new mode 100644 diff --git a/test/search_test3.cpp b/test/search_test3.cpp old mode 100755 new mode 100644 From 848b521850111109bb6b6c178a871a2c35852e80 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 11 Mar 2014 12:09:51 -0700 Subject: [PATCH 4/6] Changed parameters for the sequence-based versions of clamp from being passed by vaue to being passed by const &. Thanks to Martin Moene for the suggestion. --- include/boost/algorithm/clamp.hpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/include/boost/algorithm/clamp.hpp b/include/boost/algorithm/clamp.hpp index ae98d15..7bfa47e 100644 --- a/include/boost/algorithm/clamp.hpp +++ b/include/boost/algorithm/clamp.hpp @@ -31,8 +31,8 @@ namespace boost { namespace algorithm { /// \fn clamp ( T const& val, -/// typename boost::mpl::identity::type const& lo, -/// typename boost::mpl::identity::type const& hi, Pred p ) +/// typename boost::mpl::identity::type const & lo, +/// typename boost::mpl::identity::type const & hi, Pred p ) /// \return the value "val" brought into the range [ lo, hi ] /// using the comparison predicate p. /// If p ( val, lo ) return lo. @@ -56,8 +56,8 @@ namespace boost { namespace algorithm { /// \fn clamp ( T const& val, -/// typename boost::mpl::identity::type const& lo, -/// typename boost::mpl::identity::type const& hi ) +/// typename boost::mpl::identity::type const & lo, +/// typename boost::mpl::identity::type const & hi ) /// \return the value "val" brought into the range [ lo, hi ]. /// If the value is less than lo, return lo. /// If the value is greater than "hi", return hi. @@ -76,8 +76,8 @@ namespace boost { namespace algorithm { } /// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out, -/// std::iterator_traits::value_type lo, -/// std::iterator_traits::value_type hi ) +/// std::iterator_traits::value_type const & lo, +/// std::iterator_traits::value_type const & hi ) /// \return clamp the sequence of values [first, last) into [ lo, hi ] /// /// \param first The start of the range of values @@ -88,8 +88,8 @@ namespace boost { namespace algorithm { /// template OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out, - typename std::iterator_traits::value_type lo, - typename std::iterator_traits::value_type hi ) + typename std::iterator_traits::value_type const & lo, + typename std::iterator_traits::value_type const & hi ) { // this could also be written with bind and std::transform while ( first != last ) @@ -98,8 +98,8 @@ namespace boost { namespace algorithm { } /// \fn clamp_range ( const Range &r, OutputIterator out, -/// typename std::iterator_traits::type>::value_type lo, -/// typename std::iterator_traits::type>::value_type hi ) +/// typename std::iterator_traits::type>::value_type const & lo, +/// typename std::iterator_traits::type>::value_type const & hi ) /// \return clamp the sequence of values [first, last) into [ lo, hi ] /// /// \param r The range of values to be clamped @@ -110,16 +110,16 @@ namespace boost { namespace algorithm { template typename boost::disable_if_c::value, OutputIterator>::type clamp_range ( const Range &r, OutputIterator out, - typename std::iterator_traits::type>::value_type lo, - typename std::iterator_traits::type>::value_type hi ) + typename std::iterator_traits::type>::value_type const & lo, + typename std::iterator_traits::type>::value_type const & hi ) { return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi ); } /// \fn clamp_range ( InputIterator first, InputIterator last, OutputIterator out, -/// std::iterator_traits::value_type lo, -/// std::iterator_traits::value_type hi, Pred p ) +/// std::iterator_traits::value_type const & lo, +/// std::iterator_traits::value_type const & hi, Pred p ) /// \return clamp the sequence of values [first, last) into [ lo, hi ] /// using the comparison predicate p. /// @@ -134,8 +134,8 @@ namespace boost { namespace algorithm { /// template OutputIterator clamp_range ( InputIterator first, InputIterator last, OutputIterator out, - typename std::iterator_traits::value_type lo, - typename std::iterator_traits::value_type hi, Pred p ) + typename std::iterator_traits::value_type const & lo, + typename std::iterator_traits::value_type const & hi, Pred p ) { // this could also be written with bind and std::transform while ( first != last ) @@ -144,8 +144,8 @@ namespace boost { namespace algorithm { } /// \fn clamp_range ( const Range &r, OutputIterator out, -/// typename std::iterator_traits::type>::value_type lo, -/// typename std::iterator_traits::type>::value_type hi, +/// typename std::iterator_traits::type>::value_type const & lo, +/// typename std::iterator_traits::type>::value_type const & hi, /// Pred p ) /// \return clamp the sequence of values [first, last) into [ lo, hi ] /// using the comparison predicate p. @@ -162,8 +162,8 @@ namespace boost { namespace algorithm { template typename boost::disable_if_c::value, OutputIterator>::type clamp_range ( const Range &r, OutputIterator out, - typename std::iterator_traits::type>::value_type lo, - typename std::iterator_traits::type>::value_type hi, + typename std::iterator_traits::type>::value_type const & lo, + typename std::iterator_traits::type>::value_type const & hi, Pred p ) { return clamp_range ( boost::begin ( r ), boost::end ( r ), out, lo, hi, p ); From a4d5f17173269c4108b5b55a74798d8bb51c902b Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 19 Mar 2014 09:11:51 -0700 Subject: [PATCH 5/6] #ifdef out the four argument versions of is_permutation when we are compiling with C++14, since they're in the standard library --- include/boost/algorithm/cxx11/is_permutation.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/boost/algorithm/cxx11/is_permutation.hpp b/include/boost/algorithm/cxx11/is_permutation.hpp index 3eff5ce..ac3eb82 100644 --- a/include/boost/algorithm/cxx11/is_permutation.hpp +++ b/include/boost/algorithm/cxx11/is_permutation.hpp @@ -163,6 +163,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIt #endif +#if __cplusplus <= 201103L /// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, /// ForwardIterator2 first2, ForwardIterator2 last2 ) /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 @@ -171,7 +172,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIt /// \param last2 One past the end of the input sequence /// \param first2 The start of the second sequence /// \param last1 One past the end of the second sequence -/// \note This function is part of the C++2011 standard library. +/// \note This function is part of the C++2014 standard library. /// We will use the standard one if it is available, /// otherwise we have our own implementation. template< class ForwardIterator1, class ForwardIterator2 > @@ -198,7 +199,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, /// \param last2 One past the end of the second sequence /// \param pred The predicate to compare elements with /// -/// \note This function is part of the C++2011 standard library. +/// \note This function is part of the C++2014 standard library. /// We will use the standard one if it is available, /// otherwise we have our own implementation. template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate > @@ -211,6 +212,7 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, typename std::iterator_traits::iterator_category (), typename std::iterator_traits::iterator_category ()); } +#endif From 0f638838189fdc4ea01967a8ecbb27302195b279 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Sun, 23 Mar 2014 14:56:48 -0700 Subject: [PATCH 6/6] Rework the file layout and implementation of 'is_permutation' to match the various versions of the C++ standard. In particular, move the four iterator versions into the cxx14/ directory. --- .../boost/algorithm/cxx11/is_permutation.hpp | 58 +------------ .../boost/algorithm/cxx14/is_permutation.hpp | 86 +++++++++++++++++++ test/is_permutation_test1.cpp | 1 + 3 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 include/boost/algorithm/cxx14/is_permutation.hpp diff --git a/include/boost/algorithm/cxx11/is_permutation.hpp b/include/boost/algorithm/cxx11/is_permutation.hpp index ac3eb82..9b3bc22 100644 --- a/include/boost/algorithm/cxx11/is_permutation.hpp +++ b/include/boost/algorithm/cxx11/is_permutation.hpp @@ -9,8 +9,8 @@ /// \brief Is a sequence a permutation of another sequence /// \author Marshall Clow -#ifndef BOOST_ALGORITHM_IS_PERMUTATION_HPP -#define BOOST_ALGORITHM_IS_PERMUTATION_HPP +#ifndef BOOST_ALGORITHM_IS_PERMUTATION11_HPP +#define BOOST_ALGORITHM_IS_PERMUTATION11_HPP #include // for std::less, tie, mismatch and is_permutation (if available) #include // for std::make_pair @@ -163,58 +163,6 @@ bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, ForwardIt #endif -#if __cplusplus <= 201103L -/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, -/// ForwardIterator2 first2, ForwardIterator2 last2 ) -/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 -/// -/// \param first1 The start of the input sequence -/// \param last2 One past the end of the input sequence -/// \param first2 The start of the second sequence -/// \param last1 One past the end of the second sequence -/// \note This function is part of the C++2014 standard library. -/// We will use the standard one if it is available, -/// otherwise we have our own implementation. -template< class ForwardIterator1, class ForwardIterator2 > -bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2 ) -{ -// How should I deal with the idea that ForwardIterator1::value_type -// and ForwardIterator2::value_type could be different? Define my own comparison predicate? - return boost::algorithm::detail::is_permutation_tag ( - first1, last1, first2, last2, - std::equal_to::value_type> (), - typename std::iterator_traits::iterator_category (), - typename std::iterator_traits::iterator_category ()); -} - -/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, -/// ForwardIterator2 first2, ForwardIterator2 last2, -/// BinaryPredicate p ) -/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 -/// -/// \param first1 The start of the input sequence -/// \param last1 One past the end of the input sequence -/// \param first2 The start of the second sequence -/// \param last2 One past the end of the second sequence -/// \param pred The predicate to compare elements with -/// -/// \note This function is part of the C++2014 standard library. -/// We will use the standard one if it is available, -/// otherwise we have our own implementation. -template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate > -bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, - ForwardIterator2 first2, ForwardIterator2 last2, - BinaryPredicate pred ) -{ - return boost::algorithm::detail::is_permutation_tag ( - first1, last1, first2, last2, pred, - typename std::iterator_traits::iterator_category (), - typename std::iterator_traits::iterator_category ()); -} -#endif - - /// \fn is_permutation ( const Range &r, ForwardIterator first2 ) /// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 @@ -245,4 +193,4 @@ is_permutation ( const Range &r, ForwardIterator first2, BinaryPredicate pred ) }} -#endif // BOOST_ALGORITHM_IS_PERMUTATION_HPP +#endif // BOOST_ALGORITHM_IS_PERMUTATION11_HPP diff --git a/include/boost/algorithm/cxx14/is_permutation.hpp b/include/boost/algorithm/cxx14/is_permutation.hpp new file mode 100644 index 0000000..d8002cb --- /dev/null +++ b/include/boost/algorithm/cxx14/is_permutation.hpp @@ -0,0 +1,86 @@ +/* + Copyright (c) Marshall Clow 2014. + + 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_permutation.hpp +/// \brief Is a sequence a permutation of another sequence (four iterator versions) +/// \author Marshall Clow + +#ifndef BOOST_ALGORITHM_IS_PERMUTATION14_HPP +#define BOOST_ALGORITHM_IS_PERMUTATION14_HPP + +#include // for std::less, tie, mismatch and is_permutation (if available) +#include // for std::make_pair +#include // for std::equal_to +#include + +#include +#include + +namespace boost { namespace algorithm { + +#if __cplusplus <= 201103L +/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, +/// ForwardIterator2 first2, ForwardIterator2 last2 ) +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 +/// +/// \param first1 The start of the input sequence +/// \param last2 One past the end of the input sequence +/// \param first2 The start of the second sequence +/// \param last1 One past the end of the second sequence +/// \note This function is part of the C++2014 standard library. +/// We will use the standard one if it is available, +/// otherwise we have our own implementation. +template< class ForwardIterator1, class ForwardIterator2 > +bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2 ) +{ +// How should I deal with the idea that ForwardIterator1::value_type +// and ForwardIterator2::value_type could be different? Define my own comparison predicate? + std::pair eq = boost::algorithm::mismatch + ( first1, last1, first2, last2 ); + if ( eq.first == last1 && eq.second == last2) + return true; + return boost::algorithm::detail::is_permutation_tag ( + eq.first, last1, eq.second, last2, + std::equal_to::value_type> (), + typename std::iterator_traits::iterator_category (), + typename std::iterator_traits::iterator_category ()); +} + +/// \fn is_permutation ( ForwardIterator1 first, ForwardIterator1 last, +/// ForwardIterator2 first2, ForwardIterator2 last2, +/// BinaryPredicate p ) +/// \brief Tests to see if the sequence [first,last) is a permutation of the sequence starting at first2 +/// +/// \param first1 The start of the input sequence +/// \param last1 One past the end of the input sequence +/// \param first2 The start of the second sequence +/// \param last2 One past the end of the second sequence +/// \param pred The predicate to compare elements with +/// +/// \note This function is part of the C++2014 standard library. +/// We will use the standard one if it is available, +/// otherwise we have our own implementation. +template< class ForwardIterator1, class ForwardIterator2, class BinaryPredicate > +bool is_permutation ( ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, + BinaryPredicate pred ) +{ + std::pair eq = boost::algorithm::mismatch + ( first1, last1, first2, last2, pred ); + if ( eq.first == last1 && eq.second == last2) + return true; + return boost::algorithm::detail::is_permutation_tag ( + first1, last1, first2, last2, pred, + typename std::iterator_traits::iterator_category (), + typename std::iterator_traits::iterator_category ()); +} +#endif + +}} + +#endif // BOOST_ALGORITHM_IS_PERMUTATION14_HPP diff --git a/test/is_permutation_test1.cpp b/test/is_permutation_test1.cpp index e819643..2e1a12f 100644 --- a/test/is_permutation_test1.cpp +++ b/test/is_permutation_test1.cpp @@ -11,6 +11,7 @@ #include #include +#include #define BOOST_TEST_MAIN #include