]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Querying Algorithms//find_if |20 |
2 | ||
3 | find_if | |
4 | ======= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename Pred | |
14 | > | |
15 | struct find_if | |
16 | { | |
17 | typedef |unspecified| type; | |
18 | }; | |
19 | ||
20 | ||
21 | ||
22 | Description | |
23 | ----------- | |
24 | ||
25 | Returns an iterator to the first element in ``Sequence`` that satisfies | |
26 | the predicate ``Pred``. | |
27 | ||
28 | ||
29 | Header | |
30 | ------ | |
31 | ||
32 | .. parsed-literal:: | |
33 | ||
34 | #include <boost/mpl/find_if.hpp> | |
35 | ||
36 | ||
37 | ||
38 | Parameters | |
39 | ---------- | |
40 | ||
41 | +---------------+-------------------------------+-----------------------------------+ | |
42 | | Parameter | Requirement | Description | | |
43 | +===============+===============================+===================================+ | |
44 | | ``Sequence`` | |Forward Sequence| | A sequence to search in. | | |
45 | +---------------+-------------------------------+-----------------------------------+ | |
46 | | ``Pred`` | Unary |Lambda Expression| | A search condition. | | |
47 | +---------------+-------------------------------+-----------------------------------+ | |
48 | ||
49 | ||
50 | Expression semantics | |
51 | -------------------- | |
52 | ||
53 | For any |Forward Sequence| ``s`` and unary |Lambda Expression| ``pred``: | |
54 | ||
55 | ||
56 | .. parsed-literal:: | |
57 | ||
58 | typedef find_if<s,pred>::type i; | |
59 | ||
60 | :Return type: | |
61 | |Forward Iterator|. | |
62 | ||
63 | :Semantics: | |
64 | ``i`` is the first iterator in the range |begin/end<s>| such that | |
65 | ||
66 | .. parsed-literal:: | |
67 | ||
68 | apply< pred,deref<i>::type >::type::value == true | |
69 | ||
70 | If no such iterator exists, ``i`` is identical to ``end<s>::type``. | |
71 | ||
72 | ||
73 | Complexity | |
74 | ---------- | |
75 | ||
76 | Linear. At most ``size<s>::value`` applications of ``pred``. | |
77 | ||
78 | ||
79 | Example | |
80 | ------- | |
81 | ||
82 | .. parsed-literal:: | |
83 | ||
84 | typedef vector<char,int,unsigned,long,unsigned long> types; | |
85 | typedef find_if<types, is_same<_1,unsigned> >::type iter; | |
86 | ||
87 | BOOST_MPL_ASSERT(( is_same< deref<iter>::type, unsigned > )); | |
88 | BOOST_MPL_ASSERT_RELATION( iter::pos::value, ==, 2 ); | |
89 | ||
90 | ||
91 | See also | |
92 | -------- | |
93 | ||
94 | |Querying Algorithms|, |find|, |count_if|, |lower_bound| | |
95 | ||
96 | ||
97 |