]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/algorithm/doc/any_of.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / algorithm / doc / any_of.qbk
1 [/ File any_of.qbk]
2
3 [section:any_of any_of]
4
5 [/license
6 Copyright (c) 2010-2012 Marshall Clow
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 'boost/algorithm/cxx11/any_of.hpp' contains four variants of a single algorithm, `any_of`. The algorithm tests the elements of a sequence and returns true if any of the elements has a particular property.
13
14 The routine `any_of` takes a sequence and a predicate. It will return true if the predicate returns true for any element in the sequence.
15
16 The routine `any_of_equal` takes a sequence and a value. It will return true if any element in the sequence compares equal to the passed in value.
17
18 Both routines come in two forms; the first one takes two iterators to define the range. The second form takes a single range parameter, and uses Boost.Range to traverse it.
19
20
21 [heading interface]
22
23 The function `any_of` returns true if the predicate returns true any item in the sequence. There are two versions; one takes two iterators, and the other takes a range.
24
25 ``
26 namespace boost { namespace algorithm {
27 template<typename InputIterator, typename Predicate>
28 bool any_of ( InputIterator first, InputIterator last, Predicate p );
29 template<typename Range, typename Predicate>
30 bool any_of ( const Range &r, Predicate p );
31 }}
32 ``
33
34 The function `any_of_equal` is similar to `any_of`, but instead of taking a predicate to test the elements of the sequence, it takes a value to compare against.
35
36 ``
37 namespace boost { namespace algorithm {
38 template<typename InputIterator, typename V>
39 bool any_of_equal ( InputIterator first, InputIterator last, V const &val );
40 template<typename Range, typename V>
41 bool any_of_equal ( const Range &r, V const &val );
42 }}
43 ``
44
45 [heading Examples]
46
47 Given the container `c` containing `{ 0, 1, 2, 3, 14, 15 }`, then
48 ``
49 bool isOdd ( int i ) { return i % 2 == 1; }
50 bool lessThan10 ( int i ) { return i < 10; }
51
52 using boost::algorithm;
53 any_of ( c, isOdd ) --> true
54 any_of ( c.begin (), c.end (), lessThan10 ) --> true
55 any_of ( c.begin () + 4, c.end (), lessThan10 ) --> false
56 any_of ( c.end (), c.end (), isOdd ) --> false // empty range
57 any_of_equal ( c, 3 ) --> true
58 any_of_equal ( c.begin (), c.begin () + 3, 3 ) --> false
59 any_of_equal ( c.begin (), c.begin (), 99 ) --> false // empty range
60 ``
61
62 [heading Iterator Requirements]
63
64 `any_of` and `any_of_equal` work on all iterators except output iterators.
65
66 [heading Complexity]
67
68 All of the variants of `any_of` and `any_of_equal` run in ['O(N)] (linear) time; that is, they compare against each element in the list once. If any of the comparisons succeed, the algorithm will terminate immediately, without examining the remaining members of the sequence.
69
70 [heading Exception Safety]
71
72 All of the variants of `any_of` and `any_of_equal` take their parameters by value or const reference, and do not depend upon any global state. Therefore, all the routines in this file provide the strong exception guarantee.
73
74 [heading Notes]
75
76 * The routine `any_of` is also available as part of the C++11 standard.
77
78 * `any_of` and `any_of_equal` both return false for empty ranges, no matter what is passed to test against.
79
80 * The second parameter to `any_of_value` is a template parameter, rather than deduced from the first parameter (`std::iterator_traits<InputIterator>::value_type`) because that allows more flexibility for callers, and takes advantage of built-in comparisons for the type that is pointed to by the iterator. The function is defined to return true if, for any element in the sequence, the expression `*iter == val` evaluates to true (where `iter` is an iterator to each element in the sequence)
81
82 [endsect]
83
84 [/ File any_of.qbk
85 Copyright 2011 Marshall Clow
86 Distributed under the Boost Software License, Version 1.0.
87 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
88 ]
89