]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/doc/is_palindrome.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / algorithm / doc / is_palindrome.qbk
1 [/ File is_palindrome.qbk]
2
3 [section:is_palindrome is_palindrome]
4
5 [/license
6 Copyright (c) 2016 Alexander Zaitsev
7
8 Distributed under the Boost Software License, Version 1.0.
9 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10 ]
11
12 The header file 'is_palindrome.hpp' contains six variants of a single algorithm, is_palindrome.
13 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.
14
15 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.
16
17 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.
18 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.
19 The fifth form takes a single C-string and a predicate. The sixth form takes a single C-string.
20
21
22 [heading interface]
23
24 The function `is_palindrome` returns true if the predicate returns true any tested by algorithm items in the sequence.
25 There are six versions:
26 1) takes two iterators.
27 2) takes two iterators and a predicate.
28 3) takes a range.
29 4) takes a range and a predicate.
30 5) takes a C-string and a predicate.
31 6) takes a C-string.
32
33 ``
34 template<typename BidirectionalIterator>
35 bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end );
36 template<typename BidirectionalIterator, typename Predicate>
37 bool is_palindrome ( BidirectionalIterator begin, BidirectionalIterator end, Predicate p );
38 template<typename Range>
39 bool is_palindrome ( const Range &r );
40 template<typename Range, typename Predicate>
41 bool is_palindrome ( const Range &r, Predicate p );
42 template<typename Predicate>
43 bool is_palindrome ( const char* str, Predicate p );
44 bool is_palindrome(const char* str);
45 ``
46
47
48 [heading Examples]
49
50 Given the containers:
51 const std::list<int> empty,
52 const std::vector<char> singleElement{'z'},
53 int oddNonPalindrome[] = {3,2,2},
54 const int oddPalindrome[] = {1,2,3,2,1},
55 const int evenPalindrome[] = {1,2,2,1},
56 int evenNonPalindrome[] = {1,4,8,8}, then
57 ``
58
59 is_palindrome(empty)) --> true //empty range
60 is_palindrome(singleElement)) --> true
61 is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome))) --> false
62 is_palindrome(std::begin(evenPalindrome), std::end(evenPalindrome))) --> true
63 is_palindrome(empty.begin(), empty.end(), functorComparator())) --> true //empty range
64 is_palindrome(std::begin(oddNonPalindrome), std::end(oddNonPalindrome), funcComparator<int>)) --> false
65 is_palindrome(std::begin(oddPalindrome), std::end(oddPalindrome)) --> true
66 is_palindrome(evenPalindrome, std::equal_to<int>())) --> true
67 is_palindrome(std::begin(evenNonPalindrome), std::end(evenNonPalindrome)) --> false
68 is_palindrome("a") --> true
69 is_palindrome("aba", std::equal_to<char>()) --> true
70 ``
71
72 [heading Iterator Requirements]
73
74 `is_palindrome` work on Bidirectional and RandomAccess iterators.
75
76 [heading Complexity]
77
78 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.
79
80 [heading Exception Safety]
81
82 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.
83
84 [heading Notes]
85
86 * `is_palindrome` returns true for empty ranges, const char* null pointers and for single element ranges.
87
88 * If you use version of 'is_palindrome' without custom predicate, 'is_palindrome' uses default 'operator==()' for elements.
89
90 * Be careful with using not null pointer 'const char*' without '\0' - if you use it with 'is_palindrome', it's a undefined behaviour.
91
92 [endsect]
93
94 [/ File is_palindrome.qbk
95 Copyright 2016 Alexander Zaitsev
96 Distributed under the Boost Software License, Version 1.0.
97 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
98 ]