]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Inserters//inserter |
2 | ||
3 | .. _`inserter_`: | |
4 | ||
5 | inserter (class) | |
6 | ================ | |
7 | ||
8 | Synopsis | |
9 | -------- | |
10 | ||
11 | .. parsed-literal:: | |
12 | ||
13 | template< | |
14 | typename State | |
15 | , typename Operation | |
16 | > | |
17 | struct inserter | |
18 | { | |
19 | typedef State state; | |
20 | typedef Operation operation; | |
21 | }; | |
22 | ||
23 | ||
24 | Description | |
25 | ----------- | |
26 | ||
27 | A general-purpose model of the |Inserter| concept. | |
28 | ||
29 | ||
30 | Header | |
31 | ------ | |
32 | ||
33 | .. parsed-literal:: | |
34 | ||
35 | #include <boost/mpl/inserter.hpp> | |
36 | ||
37 | ||
38 | Model of | |
39 | -------- | |
40 | ||
41 | |Inserter| | |
42 | ||
43 | ||
44 | Parameters | |
45 | ---------- | |
46 | ||
47 | +---------------+-------------------------------+-----------------------------------+ | |
48 | | Parameter | Requirement | Description | | |
49 | +===============+===============================+===================================+ | |
50 | | ``State`` | Any type | A initial state. | | |
51 | +---------------+-------------------------------+-----------------------------------+ | |
52 | | ``Operation`` | Binary |Lambda Expression| | An output operation. | | |
53 | +---------------+-------------------------------+-----------------------------------+ | |
54 | ||
55 | Expression semantics | |
56 | -------------------- | |
57 | ||
58 | |Semantics disclaimer...| |Inserter|. | |
59 | ||
60 | For any binary |Lambda Expression| ``op`` and arbitrary type ``state``: | |
61 | ||
62 | +---------------------------+-------------------------------------------+ | |
63 | | Expression | Semantics | | |
64 | +===========================+===========================================+ | |
65 | | ``inserter<op,state>`` | An |Inserter|. | | |
66 | +---------------------------+-------------------------------------------+ | |
67 | ||
68 | Complexity | |
69 | ---------- | |
70 | ||
71 | Amortized constant time. | |
72 | ||
73 | ||
74 | Example | |
75 | ------- | |
76 | ||
77 | .. parsed-literal:: | |
78 | ||
79 | template< typename N > struct is_odd : bool_< ( N::value % 2 ) > {}; | |
80 | ||
81 | typedef copy< | |
82 | range_c<int,0,10> | |
83 | , inserter< // a filtering 'push_back' inserter | |
84 | vector<> | |
85 | , if_< is_odd<_2>, push_back<_1,_2>, _1 > | |
86 | > | |
87 | >::type odds; | |
88 | ||
89 | BOOST_MPL_ASSERT(( equal< odds, vector_c<int,1,3,5,7,9>, equal_to<_,_> > )); | |
90 | ||
91 | ||
92 | See also | |
93 | -------- | |
94 | ||
95 | |Algorithms|, |Inserter|, |Reversible Algorithm|, |front_inserter|, |back_inserter| | |
96 | ||
97 | .. |[inserter]| replace:: `inserter (class)`_ | |
98 | ||
99 | ||
100 |