Adding some includes to appease build bots. Amends r203354
[oota-llvm.git] / include / llvm / ADT / iterator_range.h
1 //===- iterator_range.h - A range adaptor for iterators ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 /// This provides a very simple, boring adaptor for a begin and end iterator
11 /// into a range type. This should be used to build range views that work well
12 /// with range based for loops and range based constructors.
13 ///
14 /// Note that code here follows more standards-based coding conventions as it
15 /// is mirroring proposed interfaces for standardization.
16 ///
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_ADT_ITERATOR_RANGE_H
20 #define LLVM_ADT_ITERATOR_RANGE_H
21
22 #include <algorithm>
23 #include <iterator>
24 #include <utility>
25
26 namespace llvm {
27
28 template <typename Range>
29 struct range_traits {
30   typedef typename Range::difference_type difference_type;
31 };
32
33 /// \brief A range adaptor for a pair of iterators.
34 ///
35 /// This just wraps two iterators into a range-compatible interface. Nothing
36 /// fancy at all.
37 template <typename IteratorT>
38 class iterator_range {
39   IteratorT begin_iterator, end_iterator;
40
41 public:
42   // FIXME: We should be using iterator_traits to determine the
43   // difference_type, but most of our iterators do not expose anything like it.
44   typedef int difference_type;
45
46   iterator_range() {}
47   iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
48       : begin_iterator(std::move(begin_iterator)),
49         end_iterator(std::move(end_iterator)) {}
50
51   IteratorT begin() const { return begin_iterator; }
52   IteratorT end() const { return end_iterator; }
53 };
54
55 /// \brief Determine the distance between the end() and begin() iterators of
56 /// a range. Analogous to std::distance().
57 template <class Range>
58 typename range_traits<Range>::difference_type distance(Range R) {
59   return std::distance(R.begin(), R.end());
60 }
61
62 /// \brief Copies members of a range into the output iterator provided.
63 /// Analogous to std::copy.
64 template <class Range, class OutputIterator>
65 OutputIterator copy(Range In, OutputIterator Result) {
66   return std::copy(In.begin(), In.end(), Result);
67 }
68 }
69
70 #endif