]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Sequences/Intrinsic Metafunctions//push_back |
2 | ||
3 | push_back | |
4 | ========= | |
5 | ||
6 | Synopsis | |
7 | -------- | |
8 | ||
9 | .. parsed-literal:: | |
10 | ||
11 | template< | |
12 | typename Sequence | |
13 | , typename T | |
14 | > | |
15 | struct push_back | |
16 | { | |
17 | typedef |unspecified| type; | |
18 | }; | |
19 | ||
20 | ||
21 | ||
22 | Description | |
23 | ----------- | |
24 | ||
25 | ``push_back`` performs an insertion at the end of the sequence with guaranteed |O(1)| | |
26 | complexity. | |
27 | ||
28 | Header | |
29 | ------ | |
30 | ||
31 | .. parsed-literal:: | |
32 | ||
33 | #include <boost/mpl/push_back.hpp> | |
34 | ||
35 | ||
36 | ||
37 | Model of | |
38 | -------- | |
39 | ||
40 | |Tag Dispatched Metafunction| | |
41 | ||
42 | ||
43 | Parameters | |
44 | ---------- | |
45 | ||
46 | +---------------+-------------------------------+-----------------------------------------------+ | |
47 | | Parameter | Requirement | Description | | |
48 | +===============+===============================+===============================================+ | |
49 | | ``Sequence`` | |Back Extensible Sequence| | A sequence to insert into. | | |
50 | +---------------+-------------------------------+-----------------------------------------------+ | |
51 | | ``T`` | Any type | The element to be inserted. | | |
52 | +---------------+-------------------------------+-----------------------------------------------+ | |
53 | ||
54 | ||
55 | Expression semantics | |
56 | -------------------- | |
57 | ||
58 | For any |Back Extensible Sequence| ``s`` and arbitrary type ``x``: | |
59 | ||
60 | ||
61 | .. parsed-literal:: | |
62 | ||
63 | typedef push_back<s,x>::type r; | |
64 | ||
65 | :Return type: | |
66 | |Back Extensible Sequence|. | |
67 | ||
68 | :Semantics: | |
69 | Equivalent to | |
70 | ||
71 | .. parsed-literal:: | |
72 | ||
73 | typedef insert< s,end<s>::type,x >::type r; | |
74 | ||
75 | ||
76 | :Postcondition: | |
77 | ``back<r>::type`` is identical to ``x``; | |
78 | ||
79 | .. parsed-literal:: | |
80 | ||
81 | size<r>::value == size<s>::value + 1 | |
82 | ||
83 | ||
84 | Complexity | |
85 | ---------- | |
86 | ||
87 | Amortized constant time. | |
88 | ||
89 | ||
90 | Example | |
91 | ------- | |
92 | ||
93 | .. parsed-literal:: | |
94 | ||
95 | typedef vector_c<bool,false,false,false, | |
96 | true,true,true,false,false> bools; | |
97 | ||
98 | typedef push_back<bools,false_>::type message; | |
99 | ||
100 | BOOST_MPL_ASSERT_RELATION( back<message>::type::value, ==, false ); | |
101 | BOOST_MPL_ASSERT_RELATION( | |
102 | ( count_if<message, equal_to<_1,false_> >::value ), ==, 6 | |
103 | ); | |
104 | ||
105 | ||
106 | See also | |
107 | -------- | |
108 | ||
109 | |Back Extensible Sequence|, |insert|, |pop_back|, |back|, |push_front| | |
110 | ||
111 | ||
112 |