]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/range/doc/reference/ranges/any_range.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / range / doc / reference / ranges / any_range.qbk
CommitLineData
7c673cae
FG
1[/
2 Copyright 2010 Neil Groves
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5/]
6[section:any_range any_range]
7
8[heading Description]
9
10`any_range` is a range that has the type information erased hence a `any_range<int, boost::forward_traversal_tag, int, std::ptrdiff_t>`
11can be used to represent a `std::vector<int>`, a `std::list<int>` or many other types.
12
13The __type_erasure_article__ covers the motivation and goals of type erasure in this context. Clearly
14my implementation is building upon a lot of prior art created by others. Thomas Becker's `any_iterator` was a strong
15influence. Adobe also have an `any_iterator` implementation, but this has very tight coupling to other parts of the
16library that precluded it from use in Boost.Range.
17Early development versions of this Range Adaptor directly used Thomas Becker's any_iterator implementation.
18Subsequently I discovered that the heap allocations of this and many other implementations cause poor
19speed performance particularly at the tails of the distribution. To solve this required a new design that
20incorporated the embedded buffer optimization.
21
22Despite the underlying `any_iterator` being the fastest available implementation, the performance overhead of `any_range` is still appreciable due to the cost of virtual function calls required to implement `increment`, `decrement`, `advance`, `equal` etc. Frequently a better design choice is to convert to a canonical form.
23
24Please see the __range_adaptors_type_erased__ for a Range Adaptor that returns `any_range` instances.
25
26[heading Synopsis]
27
28``
29template<
30 class Value
31 , class Traversal
32 , class Reference
33 , class Difference
34 , class Buffer = any_iterator_default_buffer
35>
36class any_range
37 : public iterator_range<
38 range_detail::any_iterator<
39 Value
40 , Traversal
41 , Reference
42 , Difference
43 , Buffer
44 >
45 >
46{
47 typedef range_detail::any_iterator<
48 Value
49 , Traversal
50 , Reference
51 , Difference
52 , Buffer
53 > any_iterator_type;
54
55 typedef iterator_range<any_iterator_type> base_type;
56
57 struct enabler {};
58 struct disabler {};
59public:
60 typedef any_iterator_type iterator;
61 typedef any_iterator_type const_iterator;
62
63 any_range()
64 {
65 }
66
67 any_range(const any_range& other)
68 : base_type(other)
69 {
70 }
71
72 template<class WrappedRange>
73 any_range(WrappedRange& wrapped_range)
74 : base_type(boost::begin(wrapped_range),
75 boost::end(wrapped_range))
76 {
77 }
78
79 template<class WrappedRange>
80 any_range(const WrappedRange& wrapped_range)
81 : base_type(boost::begin(wrapped_range),
82 boost::end(wrapped_range))
83 {
84 }
85
86 template<
87 class OtherValue
88 , class OtherTraversal
89 , class OtherReference
90 , class OtherDifference
91 >
92 any_range(const any_range<
93 OtherValue
94 , OtherTraversal
95 , OtherReference
96 , OtherDifference
97 , Buffer
98 >& other)
99 : base_type(boost::begin(other), boost::end(other))
100 {
101 }
102
103 template<class Iterator>
104 any_range(Iterator first, Iterator last)
105 : base_type(first, last)
106 {
107 }
108};
109``
110
111[heading Definition]
112
113Defined in header file `boost/range/any_range.hpp`
114
115[endsect]