2 Copyright (c) Alexander Zaitsev <zamazan4ik@gmail.com>, 2016
4 Distributed under the Boost Software License, Version 1.0. (See
5 accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
8 See http://www.boost.org/ for latest version.
11 /// \file is_palindrome.hpp
12 /// \brief Checks the input sequence on palindrome.
13 /// \author Alexander Zaitsev
15 #ifndef BOOST_ALGORITHM_IS_PALINDROME_HPP
16 #define BOOST_ALGORITHM_IS_PALINDROME_HPP
22 #include <boost/range/begin.hpp>
23 #include <boost/range/end.hpp>
25 namespace boost { namespace algorithm {
27 /// \fn is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p )
28 /// \return true if the entire sequence is palindrome
30 /// \param begin The start of the input sequence
31 /// \param end One past the end of the input sequence
32 /// \param p A predicate used to compare the values.
34 /// \note This function will return true for empty sequences and for palindromes.
35 /// For other sequences function will return false.
37 template <typename BidirectionalIterator, typename Predicate>
38 bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predicate p )
62 /// \fn is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end )
63 /// \return true if the entire sequence is palindrome
65 /// \param begin The start of the input sequence
66 /// \param end One past the end of the input sequence
68 /// \note This function will return true for empty sequences and for palindromes.
69 /// For other sequences function will return false.
71 template <typename BidirectionalIterator>
72 bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end)
96 /// \fn is_palindrome ( const R& range )
97 /// \return true if the entire sequence is palindrome
99 /// \param range The range to be tested.
101 /// \note This function will return true for empty sequences and for palindromes.
102 /// For other sequences function will return false.
103 /// Complexity: O(N).
104 template <typename R>
105 bool is_palindrome(const R& range)
107 return is_palindrome(boost::begin(range), boost::end(range));
110 /// \fn is_palindrome ( const R& range, Predicate p )
111 /// \return true if the entire sequence is palindrome
113 /// \param range The range to be tested.
114 /// \param p A predicate used to compare the values.
116 /// \note This function will return true for empty sequences and for palindromes.
117 /// For other sequences function will return false.
118 /// Complexity: O(N).
119 template <typename R, typename Predicate>
120 bool is_palindrome(const R& range, Predicate p)
122 return is_palindrome(boost::begin(range), boost::end(range), p);
126 /// \fn is_palindrome ( const char* str )
127 /// \return true if the entire sequence is palindrome
129 /// \param str C-string to be tested.
131 /// \note This function will return true for empty sequences and for palindromes.
132 /// For other sequences function will return false.
133 /// Complexity: O(N).
134 bool is_palindrome(const char* str)
138 return is_palindrome(str, str + strlen(str));
142 /// \fn is_palindrome ( const char* str, Predicate p )
143 /// \return true if the entire sequence is palindrome
145 /// \param str C-string to be tested.
146 /// \param p A predicate used to compare the values.
148 /// \note This function will return true for empty sequences and for palindromes.
149 /// For other sequences function will return false.
150 /// Complexity: O(N).
151 template<typename Predicate>
152 bool is_palindrome(const char* str, Predicate p)
156 return is_palindrome(str, str + strlen(str), p);
161 #endif // BOOST_ALGORITHM_IS_PALINDROME_HPP