]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/iterator/doc/quickbook/iterator.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / iterator / doc / quickbook / iterator.qbk
CommitLineData
7c673cae
FG
1
2[library Boost.Iterator
3 [/ version 1.0.1]
4 [quickbook 1.6]
5 [authors [Abrahams, David], [Siek, Jeremy], [Witt, Thomas]]
6 [copyright 2003 2005 David Abrahams Jeremy Siek Thomas Witt]
7 [category iterator]
8 [id iterator]
9 [dirname iterator]
10 [purpose
11 ]
12 [license
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or copy at
15 <ulink url="http://www.boost.org/LICENSE_1_0.txt">
16 http://www.boost.org/LICENSE_1_0.txt
17 </ulink>)
18 ]
19]
20
21[/ QuickBook Document version 1.0 ]
22
23[/ Images ]
24
25[def _note_ [$images/note.png]]
26[def _alert_ [$images/caution.png]]
27[def _detail_ [$images/note.png]]
28[def _tip_ [$images/tip.png]]
29
30[/ Links ]
31
32[def _iterator_ [@../../libs/iterator/doc/index.html Boost.Iterator]]
33
34[section:intro Introduction]
35
36[def _concepts_ [@http://www.boost.org/more/generic_programming.html#concept concepts]]
37
38The Boost Iterator Library contains two parts. The first
39is a system of _concepts_ which extend the C++ standard
40iterator requirements. The second is a framework of
41components for building iterators based on these
42extended concepts and includes several useful iterator
43adaptors. The extended iterator concepts have been
44carefully designed so that old-style iterators
45can fit in the new concepts and so that new-style
46iterators will be compatible with old-style algorithms,
47though algorithms may need to be updated if they want to
48take full advantage of the new-style iterator
49capabilities. Several components of this library have
50been accepted into the C++ standard technical report.
51The components of the Boost Iterator Library replace the
52older Boost Iterator Adaptor Library.
53
54
55[h2 New-Style Iterators]
56
57[def _N1185_ [@http://www.gotw.ca/publications/N1185.pdf N1185]]
58[def _N1211_ [@http://www.gotw.ca/publications/N1211.pdf N1211]]
59[def _GOTW_50_ [@http://www.gotw.ca/gotw/050.htm Guru of the Week]]
60
61The iterator categories defined in C++98 are extremely limiting
62because they bind together two orthogonal concepts: traversal and
63element access. For example, because a random access iterator is
64required to return a reference (and not a proxy) when dereferenced,
65it is impossible to capture the capabilities of
66`vector<bool>::iterator` using the C++98 categories. This is the
67infamous "`vector<bool>` is not a container, and its iterators
68aren't random access iterators", debacle about which Herb Sutter
69wrote two papers for the standards comittee (_N1185_ and _N1211_),
70and a _GOTW_50_. New-style iterators go well beyond
71patching up `vector<bool>`, though: there are lots of other
72iterators already in use which can't be adequately represented by
73the existing concepts. For details about the new iterator
74concepts, see our [@./new-iter-concepts.html Standard Proposal for New-Style Iterators].
75
76[h2 Iterator Facade and Adaptor]
77
78[def _facade_ [@./iterator_facade.html facade]]
79[def _adaptor_ [@./iterator_adaptor.html adaptor]]
80
81Writing standard-conforming iterators is tricky, but the need comes
82up often. In order to ease the implementation of new iterators,
83the Boost.Iterator library provides the _facade_ class template,
84which implements many useful defaults and compile-time checks
85designed to help the iterator author ensure that his iterator is
86correct.
87
88It is also common to define a new iterator that is similar to some
89underlying iterator or iterator-like type, but that modifies some
90aspect of the underlying type's behavior. For that purpose, the
91library supplies the _adaptor_ class template, which is specially
92designed to take advantage of as much of the underlying type's
93behavior as possible.
94
95Both _facade_ and _adaptor_ as well as many of the `specialized
96adaptors`_ mentioned below have been proposed for standardization
97([@./facade-and-adaptor.html Standard Proposal For Iterator Facade and Adaptor]).
98
99[h2 Specialized Adaptors]
100
101The iterator library supplies a useful suite of standard-conforming
102iterator templates based on the Boost [link
103iterator.intro.iterator_facade_and_adaptor iterator facade and adaptor]
104templates.
105
106[def _counting_ [@./counting_iterator.html `counting_iterator`]]
107[def _filter_ [@./filter_iterator.html `filter_iterator`]]
108[def _function_ [@./function_output_iterator.html `function_output_iterator`]]
109[def _indirect_ [@./indirect_iterator.html `indirect_iterator`]]
110[def _permutation_ [@./permutation_iterator.html `permutation_iterator`]]
111[def _reverse_ [@./reverse_iterator.html `reverse_iterator`]]
112[def _shared_ [@./shared_container_iterator.html `shared_container_iterator`]]
113[def _transform_ [@./transform_iterator.html `transform_iterator`]]
114[def _zip_ [@./zip_iterator.html `zip_iterator`]]
115
116[def _shared_ptr_ [@../../smart_ptr/shared_ptr.htm `shared_ptr`]]
117
118* _counting_: an iterator over a sequence of consecutive values.
119 Implements a "lazy sequence"
120
121* _filter_: an iterator over the subset of elements of some
122 sequence which satisfy a given predicate
123
124* _function_: an output iterator wrapping a unary function
125 object; each time an element is written into the dereferenced
126 iterator, it is passed as a parameter to the function object.
127
128* _indirect_: an iterator over the objects *pointed-to* by the
129 elements of some sequence.
130
131* _permutation_: an iterator over the elements of some random-access
132 sequence, rearranged according to some sequence of integer indices.
133
134* _reverse_: an iterator which traverses the elements of some
135 bidirectional sequence in reverse. Corrects many of the
136 shortcomings of C++98's ``std::reverse_iterator``.
137
138* _shared_: an iterator over elements of a container whose
139 lifetime is maintained by a _shared_ptr_ stored in the iterator.
140
141* _transform_: an iterator over elements which are the result of
142 applying some functional transformation to the elements of an
143 underlying sequence. This component also replaces the old
144 ``projection_iterator_adaptor``.
145
146* _zip_: an iterator over tuples of the elements at corresponding
147 positions of heterogeneous underlying iterators.
148
149[h2 Iterator Utilities]
150
151[h3 Traits]
152
153[def _pointee_ [@./pointee.html `pointee.hpp`]]
154[def _iterator_traits_ [@./iterator_traits.html `iterator_traits.hpp`]]
155[def _interoperable_ [@./interoperable.html `interoperable.hpp`]]
156[def _MPL_ [@../../mpl/doc/index.html [*MPL]]]
157
158* _pointee_: Provides the capability to deduce the referent types
159 of pointers, smart pointers and iterators in generic code. Used
160 in _indirect_.
161
162* _iterator_traits_: Provides _MPL_ compatible metafunctions which
163 retrieve an iterator's traits. Also corrects for the deficiencies
164 of broken implementations of `std::iterator_traits`.
165
166[\ * |interoperable|_ (PDF__): Provides an _MPL_ compatible metafunction for
167 testing iterator interoperability
168]
169
170[h3 Testing and Concept Checking]
171
172[def _iterator_concepts_ [@./iterator_concepts.html `iterator_concepts.hpp`]]
173[def _iterator_archetypes_ [@./iterator_archetypes.html `iterator_archetypes.hpp`]]
174
175* _iterator_concepts_: Concept checking classes for the new iterator concepts.
176
177* _iterator_archetypes_: Concept archetype classes for the new iterators concepts.
178
179[endsect]
180
181[include concepts.qbk]
182
183[section:generic Generic Iterators]
184
185[include facade.qbk]
186
187[include adaptor.qbk]
188
189[endsect]
190
191[include specialized_adaptors.qbk]
192
193[section:utilities Utilities]
194
195[include archetypes.qbk]
196
197[include concept_checking.qbk]
198
199[include traits.qbk]
200
201[include utilities.qbk]
202
203[endsect]
204
205[section:upgrading Upgrading from the old Boost Iterator Adaptor Library]
206
207[def _type_generator_ [@http://www.boost.org/more/generic_programming.html#type_generator type generator]]
208
209If you have been using the old Boost Iterator Adaptor library to
210implement iterators, you probably wrote a `Policies` class which
211captures the core operations of your iterator. In the new library
212design, you'll move those same core operations into the body of the
213iterator class itself. If you were writing a family of iterators,
214you probably wrote a _type_generator_ to build the
215`iterator_adaptor` specialization you needed; in the new library
216design you don't need a type generator (though may want to keep it
217around as a compatibility aid for older code) because, due to the
218use of the Curiously Recurring Template Pattern (CRTP) [Cop95]_,
219you can now define the iterator class yourself and acquire
220functionality through inheritance from `iterator_facade` or
221`iterator_adaptor`. As a result, you also get much finer control
222over how your iterator works: you can add additional constructors,
223or even override the iterator functionality provided by the
224library.
225
226
227If you're looking for the old `projection_iterator` component,
228its functionality has been merged into _transform_iterator_: as
229long as the function object's `result_type` (or the `Reference`
230template argument, if explicitly specified) is a true reference
231type, _transform_iterator_ will behave like
232`projection_iterator` used to.
233
234[endsect]
235
236[section:history History]
237
238In 2000 Dave Abrahams was writing an iterator for a container of
239pointers, which would access the pointed-to elements when
240dereferenced. Naturally, being a library writer, he decided to
241generalize the idea and the Boost Iterator Adaptor library was born.
242Dave was inspired by some writings of Andrei Alexandrescu and chose a
243policy based design (though he probably didn't capture Andrei's idea
244very well - there was only one policy class for all the iterator's
245orthogonal properties). Soon Jeremy Siek realized he would need the
246library and they worked together to produce a "Boostified" version,
247which was reviewed and accepted into the library. They wrote a paper
248and made several important revisions of the code.
249
250Eventually, several shortcomings of the older library began to make
251the need for a rewrite apparent. Dave and Jeremy started working
252at the Santa Cruz C++ committee meeting in 2002, and had quickly
253generated a working prototype. At the urging of Mat Marcus, they
254decided to use the GenVoca/CRTP pattern approach, and moved the
255policies into the iterator class itself. Thomas Witt expressed
256interest and became the voice of strict compile-time checking for
257the project, adding uses of the SFINAE technique to eliminate false
258converting constructors and operators from the overload set. He
259also recognized the need for a separate `iterator_facade`, and
260factored it out of `iterator_adaptor`. Finally, after a
261near-complete rewrite of the prototype, they came up with the
262library you see today.
263
264[:\[Coplien, 1995\] Coplien, J., Curiously Recurring Template
265 Patterns, C++ Report, February 1995, pp. 24-27.]
266
267[endsect]
268
269