Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions doc/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ boostbook standalone

###############################################################################
alias boostdoc
: algorithm ../string/doc/string_algo.xml
: ../string/doc/string_algo.xml
:
: <dependency>autodoc <dependency>../string/doc//autodoc
: <dependency>../string/doc//autodoc
: ;
explicit boostdoc ;
alias boostrelease ;
alias boostrelease : standalone ;
explicit boostrelease ;
20 changes: 17 additions & 3 deletions doc/boyer_moore.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,36 @@ public:
~boyer_moore ();

template <typename corpusIter>
corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last );
pair<corpusIter, corpusIter> operator () ( corpusIter corpus_first, corpusIter corpus_last );
};
``

and here is the corresponding procedural interface:

``
template <typename patIter, typename corpusIter>
corpusIter boyer_moore_search (
pair<corpusIter, corpusIter> 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]

Expand Down
20 changes: 17 additions & 3 deletions doc/boyer_moore_horspool.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,36 @@ public:
~boyer_moore_horspool ();

template <typename corpusIter>
corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last );
pair<corpusIter, corpusIter> operator () ( corpusIter corpus_first, corpusIter corpus_last );
};
``

and here is the corresponding procedural interface:

``
template <typename patIter, typename corpusIter>
corpusIter boyer_moore_horspool_search (
pair<corpusIter, corpusIter> 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]

Expand Down
19 changes: 16 additions & 3 deletions doc/knuth_morris_pratt.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,36 @@ public:
~knuth_morris_pratt ();

template <typename corpusIter>
corpusIter operator () ( corpusIter corpus_first, corpusIter corpus_last );
pair<corpusIter, corpusIter> operator () ( corpusIter corpus_first, corpusIter corpus_last );
};
``

and here is the corresponding procedural interface:

``
template <typename patIter, typename corpusIter>
corpusIter knuth_morris_pratt_search (
pair<corpusIter, corpusIter> 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.
Expand Down
3 changes: 1 addition & 2 deletions include/boost/algorithm/cxx14/equal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
#define BOOST_ALGORITHM_EQUAL_HPP

#include <algorithm> // for std::equal
#include <functional> // for std::binary_function
#include <iterator>

namespace boost { namespace algorithm {

namespace detail {

template <class T1, class T2>
struct eq : public std::binary_function<T1, T2, bool> {
struct eq {
bool operator () ( const T1& v1, const T2& v2 ) const { return v1 == v2 ;}
};

Expand Down
29 changes: 4 additions & 25 deletions include/boost/algorithm/is_palindrome.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace boost { namespace algorithm {
/// For other sequences function will return false.
/// Complexity: O(N).
template <typename BidirectionalIterator, typename Predicate>
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p )
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p)
{
if(begin == end)
{
Expand Down Expand Up @@ -63,34 +63,16 @@ 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.
/// Complexity: O(N).
template <typename BidirectionalIterator>
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<typename std::iterator_traits<BidirectionalIterator>::value_type> ());
}

/// \fn is_palindrome ( const R& range )
Expand Down Expand Up @@ -122,7 +104,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
///
Expand All @@ -138,7 +119,6 @@ bool is_palindrome(const char* str)
return is_palindrome(str, str + strlen(str));
}


/// \fn is_palindrome ( const char* str, Predicate p )
/// \return true if the entire sequence is palindrome
///
Expand All @@ -155,7 +135,6 @@ bool is_palindrome(const char* str, Predicate p)
return true;
return is_palindrome(str, str + strlen(str), p);
}

}}

#endif // BOOST_ALGORITHM_IS_PALINDROME_HPP
16 changes: 8 additions & 8 deletions include/boost/algorithm/searching/boyer_moore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,35 @@ mismatch on a character that _is_ in the pattern.


template<typename Iter, typename Container>
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 );

prefix[0] = 0;
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;
}
}

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<typename std::iterator_traits<patIter>::value_type> reversed(count);
(void) std::reverse_copy ( pat_first, pat_last, reversed.begin ());
(void) std::reverse_copy ( first, last, reversed.begin ());

std::vector<difference_type> prefix (count);
compute_bm_prefix ( pat_first, pat_last, prefix );
compute_bm_prefix ( first, last, prefix );

std::vector<difference_type> prefix_reversed (count);
compute_bm_prefix ( reversed.begin (), reversed.end (), prefix_reversed );
Expand Down
8 changes: 6 additions & 2 deletions include/boost/algorithm/string/detail/case_conv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ namespace boost {

// a tolower functor
template<typename CharT>
struct to_lowerF : public std::unary_function<CharT, CharT>
struct to_lowerF
{
typedef CharT argument_type;
typedef CharT result_type;
// Constructor
to_lowerF( const std::locale& Loc ) : m_Loc( &Loc ) {}

Expand All @@ -50,8 +52,10 @@ namespace boost {

// a toupper functor
template<typename CharT>
struct to_upperF : public std::unary_function<CharT, CharT>
struct to_upperF
{
typedef CharT argument_type;
typedef CharT result_type;
// Constructor
to_upperF( const std::locale& Loc ) : m_Loc( &Loc ) {}

Expand Down
2 changes: 1 addition & 1 deletion include/boost/algorithm/string/detail/find_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
5 changes: 3 additions & 2 deletions include/boost/algorithm/string/detail/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IteratorT>, SeqT >
struct copy_iterator_rangeF
{
typedef iterator_range<IteratorT> argument_type;
typedef SeqT result_type;
SeqT operator()( const iterator_range<IteratorT>& Range ) const
{
return copy_range<SeqT>(Range);
Expand Down
2 changes: 1 addition & 1 deletion test/all_of_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <list>

template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }
Expand Down
2 changes: 1 addition & 1 deletion test/any_of_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <list>

template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }
Expand Down
2 changes: 1 addition & 1 deletion test/none_of_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <list>

template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }
Expand Down
2 changes: 1 addition & 1 deletion test/one_of_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <list>

template<typename T>
struct is_ : public std::unary_function<T, bool> {
struct is_ {
is_ ( T v ) : val_ ( v ) {}
~is_ () {}
bool operator () ( T comp ) const { return val_ == comp; }
Expand Down
Loading