forked from boostorg/algorithm
		
	Fix a couple of test failures for the 1.62.0 release
This commit is contained in:
		@@ -17,6 +17,7 @@
 | 
			
		||||
 | 
			
		||||
#include <iterator>
 | 
			
		||||
#include <functional>
 | 
			
		||||
#include <cstring>
 | 
			
		||||
 | 
			
		||||
#include <boost/range/begin.hpp>
 | 
			
		||||
#include <boost/range/end.hpp>
 | 
			
		||||
@@ -34,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)
 | 
			
		||||
    {
 | 
			
		||||
@@ -70,8 +71,26 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi
 | 
			
		||||
template <typename BidirectionalIterator>
 | 
			
		||||
bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end)
 | 
			
		||||
{
 | 
			
		||||
    return is_palindrome(begin, end,
 | 
			
		||||
                         std::equal_to<typename std::iterator_traits<BidirectionalIterator>::value_type> ());
 | 
			
		||||
    if(begin == end)
 | 
			
		||||
    {
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    --end;
 | 
			
		||||
    while(begin != end)
 | 
			
		||||
    {
 | 
			
		||||
        if(!(*begin == *end))
 | 
			
		||||
        {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        ++begin;
 | 
			
		||||
        if(begin == end)
 | 
			
		||||
        {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        --end;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// \fn is_palindrome ( const R& range )
 | 
			
		||||
@@ -103,6 +122,40 @@ 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
 | 
			
		||||
///
 | 
			
		||||
/// \param str C-string to be tested.
 | 
			
		||||
///
 | 
			
		||||
/// \note This function will return true for empty sequences and for palindromes.
 | 
			
		||||
///     For other sequences function will return false.
 | 
			
		||||
///     Complexity: O(N).
 | 
			
		||||
bool is_palindrome(const char* str)
 | 
			
		||||
{
 | 
			
		||||
    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
 | 
			
		||||
///
 | 
			
		||||
/// \param str C-string to be tested.
 | 
			
		||||
/// \param p   A predicate used to compare the values.
 | 
			
		||||
///
 | 
			
		||||
/// \note This function will return true for empty sequences and for palindromes.
 | 
			
		||||
///     For other sequences function will return false.
 | 
			
		||||
///     Complexity: O(N).
 | 
			
		||||
template<typename Predicate>
 | 
			
		||||
bool is_palindrome(const char* str, Predicate p)
 | 
			
		||||
{
 | 
			
		||||
    if(!str)
 | 
			
		||||
	    return true;
 | 
			
		||||
    return is_palindrome(str, str + strlen(str), p);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
#endif // BOOST_ALGORITHM_IS_PALINDROME_HPP
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user