From b913bd485a373b699ef15f5c1870ad2fcd40d839 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Tue, 29 Apr 2014 01:57:35 +0000 Subject: [PATCH] [ADT] Make the iterator adaptor utility a touch more general by requiring full control over the various parameters to the std::iterator concept / trait thing. This is a precursor for adjusting these things to where you can write a bidirectional iterator wrapping a random access iterator with custom increment and decrement logic. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207487 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/iterator.h | 27 +++++++++++++++++---------- include/llvm/Analysis/LazyCallGraph.h | 5 +++-- include/llvm/IR/User.h | 5 +++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/include/llvm/ADT/iterator.h b/include/llvm/ADT/iterator.h index af9b85c56c9..8d6a8eb163f 100644 --- a/include/llvm/ADT/iterator.h +++ b/include/llvm/ADT/iterator.h @@ -97,14 +97,19 @@ struct iterator_facade_base /// This class can be used through CRTP to adapt one iterator into another. /// Typically this is done through providing in the derived class a custom \c /// operator* implementation. Other methods can be overridden as well. -template > +template < + typename DerivedT, typename WrappedIteratorT, + typename IteratorCategoryT = + typename std::iterator_traits::iterator_category, + typename T = typename std::iterator_traits::value_type, + typename DifferenceTypeT = + typename std::iterator_traits::difference_type, + typename PointerT = T *, typename ReferenceT = T &, + // Don't provide these, they are mostly to act as aliases below. + typename WrappedTraitsT = std::iterator_traits> class iterator_adaptor_base - : public iterator_facade_base< - DerivedT, typename WrappedTraitsT::iterator_category, T, - typename WrappedTraitsT::difference_type, PointerT, ReferenceT> { + : public iterator_facade_base { typedef typename iterator_adaptor_base::iterator_facade_base BaseT; protected: @@ -123,7 +128,7 @@ protected: : I(std::forward(u)) {} public: - typedef typename WrappedTraitsT::difference_type difference_type; + typedef DifferenceTypeT difference_type; DerivedT &operator+=(difference_type n) { I += n; @@ -168,8 +173,10 @@ template ())>::type> struct pointee_iterator - : iterator_adaptor_base, - WrappedIteratorT, T> { + : iterator_adaptor_base< + pointee_iterator, WrappedIteratorT, + typename std::iterator_traits::iterator_category, + T> { pointee_iterator() {} template pointee_iterator(U &&u) diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index e4069819524..7f9a43aba36 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -113,8 +113,9 @@ public: /// be scanned for "calls" or uses of functions and its child information /// will be constructed. All of these results are accumulated and cached in /// the graph. - class iterator : public iterator_adaptor_base< - iterator, NodeVectorImplT::iterator, Node> { + class iterator + : public iterator_adaptor_base { friend class LazyCallGraph; friend class LazyCallGraph::Node; diff --git a/include/llvm/IR/User.h b/include/llvm/IR/User.h index 453b6ad1699..bc7696bdaf5 100644 --- a/include/llvm/IR/User.h +++ b/include/llvm/IR/User.h @@ -131,8 +131,9 @@ public: /// Convenience iterator for directly iterating over the Values in the /// OperandList struct value_op_iterator - : iterator_adaptor_base { + : iterator_adaptor_base { explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {} Value *operator*() const { return *I; } -- 2.34.1