[/ File is_palindrome.qbk] [section:is_palindrome is_palindrome] [/license Copyright (c) 2016 Alexander Zaitsev Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ] The header file 'is_palindrome.hpp' contains six variants of a single algorithm, is_palindrome. The algorithm tests the sequence and returns true if the sequence is a palindrome; i.e, it is identical when traversed either backwards or frontwards. The routine `is_palindrome` takes a sequence and, optionally, a predicate. It will return true if the predicate returns true for tested elements by algorithm in the sequence. The routine come in 6 forms; the first one takes two iterators to define the range. The second form takes two iterators to define the range and a predicate. The third form takes a single range parameter, and uses Boost.Range to traverse it. The fourth form takes a single range parameter ( uses Boost.Range to traverse it) and a predicate. The fifth form takes a single C-string and a predicate. The sixth form takes a single C-string. [heading interface] The function `is_palindrome` returns true if the predicate returns true any tested by algorithm items in the sequence. There are six versions: 1) takes two iterators. 2) takes two iterators and a predicate. 3) takes a range. 4) takes a range and a predicate. 5) takes a C-string and a predicate. 6) takes a C-string. `` template bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end ); template bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p ); template bool is_palindrome ( const Range &r ); template bool is_palindrome ( const Range &r, Predicate p ); template bool is_palindrome ( const char* str, Predicate p ); bool is_palindrome(const char* str); `` [heading Examples] Given the containers: const std::list empty, const std::vector singleElement{'z'}, int oddNonPalindrome[] = {3,2,2}, const int oddPalindrome[] = {1,2,3,2,1}, const int evenPalindrome[] = {1,2,2,1}, int evenNonPalindrome[] = {1,4,8,8}, then `` is_palindrome(empty)) --> true //empty range is_palindrome(singleElement)) --> true is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome))) --> false is_palindrome(std::begin(evenPalindrome), std::end(evenPalindrome))) --> true is_palindrome(empty.begin(), empty.end(), functorComparator())) --> true //empty range is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome), funcComparator)) --> false is_palindrome(std::begin(oddPalindrome), std::end(oddPalindrome)) --> true is_palindrome(evenPalindrome, std::equal_to())) --> true is_palindrome(std::begin(evenNonPalindrome), std::end(evenNonPalindrome)) --> false is_palindrome("a") --> true is_palindrome("aba", std::equal_to()) --> true `` [heading Iterator Requirements] `is_palindrome` work on Bidirectional and RandomAccess iterators. [heading Complexity] All of the variants of `is_palindrome` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons not succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence. [heading Exception Safety] All of the variants of `is_palindrome` take their parameters by value, const pointer or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee. [heading Notes] * `is_palindrome` returns true for empty ranges, const char* null pointers and for single element ranges. * If you use version of 'is_palindrome' without custom predicate, 'is_palindrome' uses default 'operator==()' for elements. * Be careful with using not null pointer 'const char*' without '\0' - if you use it with 'is_palindrome', it's a undefined behaviour. [endsect] [/ File is_palindrome.qbk Copyright 2016 Alexander Zaitsev Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt). ]