Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 7d4afb2

Browse files
committed
Removing llvm::distance and llvm::copy for iterator_range based on post-commit review feedback. Adding an explicit range-based constructor to SmallVector, which supersedes the llvm::copy functionality.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203460 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ffb6f6e commit 7d4afb2

File tree

2 files changed

+7
-25
lines changed

2 files changed

+7
-25
lines changed

include/llvm/ADT/SmallVector.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_ADT_SMALLVECTOR_H
1515
#define LLVM_ADT_SMALLVECTOR_H
1616

17+
#include "llvm/ADT/iterator_range.h"
1718
#include "llvm/Support/AlignOf.h"
1819
#include "llvm/Support/Compiler.h"
1920
#include "llvm/Support/MathExtras.h"
@@ -870,6 +871,12 @@ class SmallVector : public SmallVectorImpl<T> {
870871
this->append(S, E);
871872
}
872873

874+
template <typename RangeTy>
875+
explicit SmallVector(const llvm::iterator_range<RangeTy> R)
876+
: SmallVectorImpl<T>(N) {
877+
this->append(R.begin(), R.end());
878+
}
879+
873880
SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(N) {
874881
if (!RHS.empty())
875882
SmallVectorImpl<T>::operator=(RHS);

include/llvm/ADT/iterator_range.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,10 @@
1919
#ifndef LLVM_ADT_ITERATOR_RANGE_H
2020
#define LLVM_ADT_ITERATOR_RANGE_H
2121

22-
#include <algorithm>
23-
#include <iterator>
2422
#include <utility>
2523

2624
namespace llvm {
2725

28-
template <typename Range>
29-
struct range_traits {
30-
typedef typename Range::difference_type difference_type;
31-
};
32-
3326
/// \brief A range adaptor for a pair of iterators.
3427
///
3528
/// This just wraps two iterators into a range-compatible interface. Nothing
@@ -39,10 +32,6 @@ class iterator_range {
3932
IteratorT begin_iterator, end_iterator;
4033

4134
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-
4635
iterator_range() {}
4736
iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
4837
: begin_iterator(std::move(begin_iterator)),
@@ -51,20 +40,6 @@ class iterator_range {
5140
IteratorT begin() const { return begin_iterator; }
5241
IteratorT end() const { return end_iterator; }
5342
};
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-
}
6843
}
6944

7045
#endif

0 commit comments

Comments
 (0)