]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Querying Algorithms//max_element |90 |
2 | ||
3 | max_element | |
4 | =========== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename Pred = less<_1,_2> | |
14 | > | |
15 | struct max_element | |
16 | { | |
17 | typedef |unspecified| type; | |
18 | }; | |
19 | ||
20 | ||
21 | ||
22 | Description | |
23 | ----------- | |
24 | ||
25 | Returns an iterator to the largest element in ``Sequence``. | |
26 | ||
27 | ||
28 | Header | |
29 | ------ | |
30 | ||
31 | .. parsed-literal:: | |
32 | ||
33 | #include <boost/mpl/max_element.hpp> | |
34 | ||
35 | ||
36 | Parameters | |
37 | ---------- | |
38 | ||
39 | +---------------+-------------------------------+-----------------------------------+ | |
40 | | Parameter | Requirement | Description | | |
41 | +===============+===============================+===================================+ | |
42 | |``Sequence`` | |Forward Sequence| | A sequence to be searched. | | |
43 | +---------------+-------------------------------+-----------------------------------+ | |
44 | | ``Pred`` | Binary |Lambda Expression| | A comparison criteria. | | |
45 | +---------------+-------------------------------+-----------------------------------+ | |
46 | ||
47 | ||
48 | Expression semantics | |
49 | -------------------- | |
50 | ||
51 | ||
52 | For any |Forward Sequence| ``s`` and binary |Lambda Expression| ``pred``: | |
53 | ||
54 | ||
55 | .. parsed-literal:: | |
56 | ||
57 | typedef max_element<s,pred>::type i; | |
58 | ||
59 | :Return type: | |
60 | |Forward Iterator|. | |
61 | ||
62 | :Semantics: | |
63 | ``i`` is the first iterator in |begin/end<s>| such that for every iterator ``j`` | |
64 | in |begin/end<s>|, | |
65 | ||
66 | .. parsed-literal:: | |
67 | ||
68 | apply< pred, deref<i>::type, deref<j>::type >::type::value == false | |
69 | ||
70 | ||
71 | Complexity | |
72 | ---------- | |
73 | ||
74 | Linear. Zero comparisons if ``s`` is empty, otherwise exactly ``size<s>::value - 1`` | |
75 | comparisons. | |
76 | ||
77 | ||
78 | Example | |
79 | ------- | |
80 | ||
81 | .. parsed-literal:: | |
82 | ||
83 | typedef vector<bool,char[50],long,double> types; | |
84 | typedef max_element< | |
85 | transform_view< types,sizeof_<_1> > | |
86 | >::type iter; | |
87 | ||
88 | BOOST_MPL_ASSERT(( is_same< deref<iter::base>::type, char[50]> )); | |
89 | ||
90 | ||
91 | See also | |
92 | -------- | |
93 | ||
94 | |Querying Algorithms|, |min_element|, |find_if|, |upper_bound|, |find| | |
95 | ||
96 | ||
97 |