summaryrefslogtreecommitdiff
path: root/boost/algorithm/is_palindrome.hpp
diff options
context:
space:
mode:
authorDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:24:46 +0900
committerDongHun Kwak <dh0128.kwak@samsung.com>2017-09-13 11:25:39 +0900
commit4fadd968fa12130524c8380f33fcfe25d4de79e5 (patch)
treefd26a490cd15388d42fc6652b3c5c13012e7f93e /boost/algorithm/is_palindrome.hpp
parentb5c87084afaef42b2d058f68091be31988a6a874 (diff)
downloadboost-upstream/1.65.0.tar.gz
boost-upstream/1.65.0.tar.bz2
boost-upstream/1.65.0.zip
Imported Upstream version 1.65.0upstream/1.65.0
Change-Id: Icf8400b375482cb11bcf77440a6934ba360d6ba4 Signed-off-by: DongHun Kwak <dh0128.kwak@samsung.com>
Diffstat (limited to 'boost/algorithm/is_palindrome.hpp')
-rw-r--r--boost/algorithm/is_palindrome.hpp29
1 files changed, 4 insertions, 25 deletions
diff --git a/boost/algorithm/is_palindrome.hpp b/boost/algorithm/is_palindrome.hpp
index cc63e18075..09881109a3 100644
--- a/boost/algorithm/is_palindrome.hpp
+++ b/boost/algorithm/is_palindrome.hpp
@@ -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)
{
@@ -63,7 +63,7 @@ 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.
@@ -71,26 +71,8 @@ bool is_palindrome(BidirectionalIterator begin, BidirectionalIterator end, Predi
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 )
@@ -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
///
@@ -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
///
@@ -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