]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | .. Algorithms/Concepts//Inserter |
2 | ||
3 | Inserter | |
4 | ======== | |
5 | ||
6 | Description | |
7 | ----------- | |
8 | ||
9 | An |Inserter| is a compile-time substitute for STL |Output Iterator|. | |
10 | Under the hood, it's simply a type holding | |
11 | two entities: a *state* and an *operation*. When passed to a | |
12 | |transformation algorithm|, the inserter's binary operation is | |
13 | invoked for every element that would normally be written into the | |
14 | output iterator, with the element itself (as the second | |
15 | argument) and the result of the previous operation's invocation |--| or, | |
16 | for the very first element, the inserter's initial state. | |
17 | ||
18 | Technically, instead of taking a single inserter parameter, | |
19 | |transformation algorithms| could accept the state and the "output" | |
20 | operation separately. Grouping these in a single parameter entity, | |
21 | however, brings the algorithms semantically and syntactically closer to | |
22 | their STL counterparts, significantly simplifying many of the common | |
23 | use cases. | |
24 | ||
25 | ||
26 | Valid expressions | |
27 | ----------------- | |
28 | ||
29 | |In the following table...| ``in`` is a model of |Inserter|. | |
30 | ||
31 | +-----------------------+-------------------------------+ | |
32 | | Expression | Type | | |
33 | +=======================+===============================+ | |
34 | | ``in::state`` | Any type | | |
35 | +-----------------------+-------------------------------+ | |
36 | | ``in::operation`` | Binary |Lambda Expression| | | |
37 | +-----------------------+-------------------------------+ | |
38 | ||
39 | ||
40 | Expression semantics | |
41 | -------------------- | |
42 | ||
43 | +-----------------------+-------------------------------------------+ | |
44 | | Expression | Semantics | | |
45 | +=======================+===========================================+ | |
46 | | ``in::state`` | The inserter's initial state. | | |
47 | +-----------------------+-------------------------------------------+ | |
48 | | ``in::operation`` | The inserter's "output" operation. | | |
49 | +-----------------------+-------------------------------------------+ | |
50 | ||
51 | ||
52 | Example | |
53 | ------- | |
54 | ||
55 | .. parsed-literal:: | |
56 | ||
57 | typedef transform< | |
58 | range_c<int,0,10> | |
59 | , plus<_1,_1> | |
60 | , back_inserter< vector0<> > | |
61 | >::type result; | |
62 | ||
63 | ||
64 | Models | |
65 | ------ | |
66 | ||
67 | * |[inserter]| | |
68 | * |front_inserter| | |
69 | * |back_inserter| | |
70 | ||
71 | See also | |
72 | -------- | |
73 | ||
74 | |Algorithms|, |Transformation Algorithms|, |[inserter]|, |front_inserter|, |back_inserter| | |
75 | ||
76 | ||
77 |