]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Sequences/Intrinsic Metafunctions//front |
2 | ||
3 | front | |
4 | ===== | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | > | |
14 | struct front | |
15 | { | |
16 | typedef |unspecified| type; | |
17 | }; | |
18 | ||
19 | ||
20 | ||
21 | Description | |
22 | ----------- | |
23 | ||
24 | Returns the first element in the sequence. | |
25 | ||
26 | ||
27 | Header | |
28 | ------ | |
29 | ||
30 | .. parsed-literal:: | |
31 | ||
32 | #include <boost/mpl/front.hpp> | |
33 | ||
34 | ||
35 | Model of | |
36 | -------- | |
37 | ||
38 | |Tag Dispatched Metafunction| | |
39 | ||
40 | ||
41 | Parameters | |
42 | ---------- | |
43 | ||
44 | +---------------+-----------------------+-----------------------------------------------+ | |
45 | | Parameter | Requirement | Description | | |
46 | +===============+=======================+===============================================+ | |
47 | | ``Sequence`` | |Forward Sequence| | A sequence to be examined. | | |
48 | +---------------+-----------------------+-----------------------------------------------+ | |
49 | ||
50 | ||
51 | Expression semantics | |
52 | -------------------- | |
53 | ||
54 | For any |Forward Sequence| ``s``: | |
55 | ||
56 | ||
57 | .. parsed-literal:: | |
58 | ||
59 | typedef front<s>::type t; | |
60 | ||
61 | :Return type: | |
62 | A type. | |
63 | ||
64 | :Precondition: | |
65 | ``empty<s>::value == false``. | |
66 | ||
67 | :Semantics: | |
68 | Equivalent to | |
69 | ||
70 | .. parsed-literal:: | |
71 | ||
72 | typedef deref< begin<s>::type >::type t; | |
73 | ||
74 | ||
75 | ||
76 | Complexity | |
77 | ---------- | |
78 | ||
79 | Amortized constant time. | |
80 | ||
81 | ||
82 | Example | |
83 | ------- | |
84 | ||
85 | .. parsed-literal:: | |
86 | ||
87 | typedef list<long>::type types1; | |
88 | typedef list<int,long>::type types2; | |
89 | typedef list<char,int,long>::type types3; | |
90 | ||
91 | BOOST_MPL_ASSERT(( is_same< front<types1>::type, long > )); | |
92 | BOOST_MPL_ASSERT(( is_same< front<types2>::type, int> )); | |
93 | BOOST_MPL_ASSERT(( is_same< front<types3>::type, char> )); | |
94 | ||
95 | ||
96 | ||
97 | See also | |
98 | -------- | |
99 | ||
100 | |Forward Sequence|, |back|, |push_front|, |begin|, |deref|, |at| | |
101 | ||
102 | ||
103 |