[llvm] r207487 - [ADT] Make the iterator adaptor utility a touch more general by
Chandler Carruth
chandlerc at gmail.com
Mon Apr 28 18:57:35 PDT 2014
Author: chandlerc
Date: Mon Apr 28 20:57:35 2014
New Revision: 207487
URL: http://llvm.org/viewvc/llvm-project?rev=207487&view=rev
Log:
[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.
Modified:
llvm/trunk/include/llvm/ADT/iterator.h
llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
llvm/trunk/include/llvm/IR/User.h
Modified: llvm/trunk/include/llvm/ADT/iterator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/iterator.h?rev=207487&r1=207486&r2=207487&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/iterator.h (original)
+++ llvm/trunk/include/llvm/ADT/iterator.h Mon Apr 28 20:57:35 2014
@@ -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 <typename DerivedT, typename WrappedIteratorT, typename T,
- typename PointerT = T *, typename ReferenceT = T &,
- // Don't provide these, they are mostly to act as aliases below.
- typename WrappedTraitsT = std::iterator_traits<WrappedIteratorT>>
+template <
+ typename DerivedT, typename WrappedIteratorT,
+ typename IteratorCategoryT =
+ typename std::iterator_traits<WrappedIteratorT>::iterator_category,
+ typename T = typename std::iterator_traits<WrappedIteratorT>::value_type,
+ typename DifferenceTypeT =
+ typename std::iterator_traits<WrappedIteratorT>::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<WrappedIteratorT>>
class iterator_adaptor_base
- : public iterator_facade_base<
- DerivedT, typename WrappedTraitsT::iterator_category, T,
- typename WrappedTraitsT::difference_type, PointerT, ReferenceT> {
+ : public iterator_facade_base<DerivedT, IteratorCategoryT, T,
+ DifferenceTypeT, PointerT, ReferenceT> {
typedef typename iterator_adaptor_base::iterator_facade_base BaseT;
protected:
@@ -123,7 +128,7 @@ protected:
: I(std::forward<U &&>(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 <typename WrappedIteratorT,
typename T = typename std::remove_reference<
decltype(**std::declval<WrappedIteratorT>())>::type>
struct pointee_iterator
- : iterator_adaptor_base<pointee_iterator<WrappedIteratorT>,
- WrappedIteratorT, T> {
+ : iterator_adaptor_base<
+ pointee_iterator<WrappedIteratorT>, WrappedIteratorT,
+ typename std::iterator_traits<WrappedIteratorT>::iterator_category,
+ T> {
pointee_iterator() {}
template <typename U>
pointee_iterator(U &&u)
Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=207487&r1=207486&r2=207487&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
+++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Mon Apr 28 20:57:35 2014
@@ -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<iterator, NodeVectorImplT::iterator,
+ std::random_access_iterator_tag, Node> {
friend class LazyCallGraph;
friend class LazyCallGraph::Node;
Modified: llvm/trunk/include/llvm/IR/User.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/User.h?rev=207487&r1=207486&r2=207487&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/User.h (original)
+++ llvm/trunk/include/llvm/IR/User.h Mon Apr 28 20:57:35 2014
@@ -131,8 +131,9 @@ public:
/// Convenience iterator for directly iterating over the Values in the
/// OperandList
struct value_op_iterator
- : iterator_adaptor_base<value_op_iterator, op_iterator, Value *, Value *,
- Value *> {
+ : iterator_adaptor_base<value_op_iterator, op_iterator,
+ std::random_access_iterator_tag, Value *,
+ ptrdiff_t, Value *, Value *> {
explicit value_op_iterator(Use *U = nullptr) : iterator_adaptor_base(U) {}
Value *operator*() const { return *I; }
More information about the llvm-commits
mailing list