]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/icl/doc/functions_element_iteration.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / icl / doc / functions_element_iteration.qbk
CommitLineData
7c673cae
FG
1[/
2 Copyright (c) 2008-2009 Joachim Faulhaber
3
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7]
8
9
10[/ //= Element iteration ===================================================================]
11[section Element iteration]
12
13This section refers to ['*element iteration*] over ['*interval containers*].
14Element iterators are available as associated types on interval sets and interval maps.
15
16[table
17[[Variant] [Associated element iterator type for interval container `T`]]
18[[forward] [`T::element_iterator`] ]
19[[const forward][`T::element_const_iterator`] ]
20[[reverse] [`T::element_reverse_iterator`] ]
21[[const reverse][`T::element_const_reverse_iterator`] ]
22]
23
24There are also associated iterators types
25`T::iterator`, `T::const_iterator`,
26`T::reverse_iterator` and `T::reverse_const_iterator`
27on interval containers.
28These are ['*segment iterators*]. Segment iterators are
29"first citizen iterators". [/ NOTE Identical to interface.qbk from here]
30Iteration over segments is fast, compared to an iteration over elements,
31particularly if intervals are large.
32But if we want to view our interval containers as containers
33of elements that are usable with std::algoritms, we need to
34iterate over elements.
35
36Iteration over elements . . .
37
38* is possible only for integral or discrete `domain_types`
39* can be very ['*slow*] if the intervals are very large.
40* and is therefore ['*depreciated*]
41
42On the other hand, sometimes iteration over interval containers
43on the element level might be desired, if you have some
44interface that works for `std::SortedAssociativeContainers` of
45elements and you need to quickly use it with an interval container.
46Accepting the poorer performance might be less bothersome at times
47than adjusting your whole interface for segment iteration.
48
49[caution So we advice you to choose element iteration over
50interval containers ['*judiciously*]. Do not use element iteration
51['*by default or habitual*]. Always try to achieve results using
52member functions, global functions or operators
53(preferably inplace versions)
54or iteration over segments first.]
55
56
57[table
58[[['*Synopsis Complexities*]] [__ch_itv_sets__][__ch_itv_maps__]]
59[[`J elements_begin(T&)`] [__O1__] [__O1__] ]
60[[`J elements_end(T&)`] [__O1__] [__O1__] ]
61[[`J elements_rbegin(T&)`] [__O1__] [__O1__] ]
62[[`J elements_rend(T&)`] [__O1__] [__O1__] ]
63]
64
65[table
66[[['*Element iteration*]] [Description] ]
67[[`` element_iterator elements_begin(T&)
68element_const_iterator elements_begin(const T&)``] [Returns an element iterator to the first element of the container.] ]
69[[`` element_iterator elements_end(T&)
70element_const_iterator elements_end(const T&)``] [Returns an element iterator to a position `elements_end(c)` after the last element of the container.]]
71[[`` element_reverse_iterator elements_rbegin(T&)
72element_const_reverse_iterator elements_rbegin(const T&)``] [Returns a reverse element iterator to the last element of the container.] ]
73[[`` element_reverse_iterator elements_rend(T&)
74element_const_reverse_iterator elements_rend(const T&)``] [Returns a reverse element iterator to a position `elements_rend(c)` before the first element of the container.]]
75]
76
77['*Example*]
78
79``
80interval_set<int> inter_set;
81inter_set.add(interval<int>::right_open(0,3))
82 .add(interval<int>::right_open(7,9));
83
84for(interval_set<int>::element_const_iterator creeper = elements_begin(inter_set);
85 creeper != elements_end(inter_set); ++creeper)
86 cout << *creeper << " ";
87cout << endl;
88//Program output: 0 1 2 7 8
89
90for(interval_set<int>::element_reverse_iterator repeerc = elements_rbegin(inter_set);
91 repeerc != elements_rend(inter_set); ++repeerc)
92 cout << *repeerc << " ";
93cout << endl;
94//Program output: 8 7 2 1 0
95``
96
97['*See also . . .*]
98[table
99[]
100[[[link boost_icl.function_reference.iterator_related ['*Segment iteration*]] ]]
101]
102
103['*Back to section . . .*]
104[table
105[]
106[[[link function_synopsis_table ['*Function Synopsis*]]]]
107[[[link boost_icl.interface ['*Interface*]] ]]
108]
109
110[endsect][/ Element iteration]
111
112