Add some utilities to iterator_range for trimming a range and constructing one from a container.

To be used in clang in a follow-up commit.

llvm-svn: 242823
This commit is contained in:
David Blaikie 2015-07-21 18:37:12 +00:00
parent 87dff0e05a
commit adc8d721e0
1 changed files with 12 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#define LLVM_ADT_ITERATOR_RANGE_H #define LLVM_ADT_ITERATOR_RANGE_H
#include <utility> #include <utility>
#include <iterator>
namespace llvm { namespace llvm {
@ -32,6 +33,12 @@ class iterator_range {
IteratorT begin_iterator, end_iterator; IteratorT begin_iterator, end_iterator;
public: public:
//TODO: Add SFINAE to test that the Container's iterators match the range's
// iterators.
template <typename Container>
iterator_range(Container &&c)
//TODO: Consider ADL/non-member begin/end calls.
: begin_iterator(c.begin()), end_iterator(c.end()) {}
iterator_range(IteratorT begin_iterator, IteratorT end_iterator) iterator_range(IteratorT begin_iterator, IteratorT end_iterator)
: begin_iterator(std::move(begin_iterator)), : begin_iterator(std::move(begin_iterator)),
end_iterator(std::move(end_iterator)) {} end_iterator(std::move(end_iterator)) {}
@ -51,6 +58,11 @@ template <class T> iterator_range<T> make_range(T x, T y) {
template <typename T> iterator_range<T> make_range(std::pair<T, T> p) { template <typename T> iterator_range<T> make_range(std::pair<T, T> p) {
return iterator_range<T>(std::move(p.first), std::move(p.second)); return iterator_range<T>(std::move(p.first), std::move(p.second));
} }
template<typename T>
iterator_range<decltype(begin(std::declval<T>()))> drop_begin(T &&t, int n) {
return make_range(std::next(begin(t), n), end(t));
}
} }
#endif #endif