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