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)
74 return is_palindrome(begin, end,
75 std::equal_to<typename std::iterator_traits<BidirectionalIterator>::value_type> ());
78 /// \fn is_palindrome ( const R& range )
79 /// \return true if the entire sequence is palindrome
81 /// \param range The range to be tested.
83 /// \note This function will return true for empty sequences and for palindromes.
84 /// For other sequences function will return false.
87 bool is_palindrome(const R& range)
89 return is_palindrome(boost::begin(range), boost::end(range));
92 /// \fn is_palindrome ( const R& range, Predicate p )
93 /// \return true if the entire sequence is palindrome
95 /// \param range The range to be tested.
96 /// \param p A predicate used to compare the values.
98 /// \note This function will return true for empty sequences and for palindromes.
99 /// For other sequences function will return false.
100 /// Complexity: O(N).
101 template <typename R, typename Predicate>
102 bool is_palindrome(const R& range, Predicate p)
104 return is_palindrome(boost::begin(range), boost::end(range), p);
107 /// \fn is_palindrome ( const char* str )
108 /// \return true if the entire sequence is palindrome
110 /// \param str C-string to be tested.
112 /// \note This function will return true for empty sequences and for palindromes.
113 /// For other sequences function will return false.
114 /// Complexity: O(N).
115 bool is_palindrome(const char* str)
119 return is_palindrome(str, str + strlen(str));
122 /// \fn is_palindrome ( const char* str, Predicate p )
123 /// \return true if the entire sequence is palindrome
125 /// \param str C-string to be tested.
126 /// \param p A predicate used to compare the values.
128 /// \note This function will return true for empty sequences and for palindromes.
129 /// For other sequences function will return false.
130 /// Complexity: O(N).
131 template<typename Predicate>
132 bool is_palindrome(const char* str, Predicate p)
136 return is_palindrome(str, str + strlen(str), p);
140 #endif // BOOST_ALGORITHM_IS_PALINDROME_HPP