23
23
24
24
namespace llvm {
25
25
26
+ template <typename Range>
27
+ struct range_traits {
28
+ typedef typename Range::difference_type difference_type;
29
+ };
30
+
26
31
// / \brief A range adaptor for a pair of iterators.
27
32
// /
28
33
// / This just wraps two iterators into a range-compatible interface. Nothing
@@ -32,6 +37,10 @@ class iterator_range {
32
37
IteratorT begin_iterator, end_iterator;
33
38
34
39
public:
40
+ // FIXME: We should be using iterator_traits to determine the
41
+ // difference_type, but most of our iterators do not expose anything like it.
42
+ typedef int difference_type;
43
+
35
44
iterator_range () {}
36
45
iterator_range (IteratorT begin_iterator, IteratorT end_iterator)
37
46
: begin_iterator(std::move(begin_iterator)),
@@ -41,6 +50,19 @@ class iterator_range {
41
50
IteratorT end () const { return end_iterator; }
42
51
};
43
52
53
+ // / \brief Determine the distance between the end() and begin() iterators of
54
+ // / a range. Analogous to std::distance().
55
+ template <class Range >
56
+ typename range_traits<Range>::difference_type distance (Range R) {
57
+ return std::distance (R.begin (), R.end ());
58
+ }
59
+
60
+ // / \brief Copies members of a range into the output iterator provided.
61
+ // / Analogous to std::copy.
62
+ template <class Range , class OutputIterator >
63
+ OutputIterator copy (Range In, OutputIterator Result) {
64
+ return std::copy (In.begin (), In.end (), Result);
65
+ }
44
66
}
45
67
46
68
#endif
0 commit comments