[PATCH] D23217: [ADT] Change iterator_adaptor_base's default template arguments to forward more underlying typedefs

Tim Shen via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 5 11:40:07 PDT 2016


timshen updated this revision to Diff 66986.
timshen added a comment.

Added a test.


https://reviews.llvm.org/D23217

Files:
  include/llvm/ADT/iterator.h
  unittests/Support/IteratorTest.cpp

Index: unittests/Support/IteratorTest.cpp
===================================================================
--- unittests/Support/IteratorTest.cpp
+++ unittests/Support/IteratorTest.cpp
@@ -98,4 +98,14 @@
   EXPECT_EQ(End, I);
 }
 
+TEST(IteratorAdaptorBaseTest, ForwardTypedefs) {
+  struct WeirdIter : std::iterator<std::input_iterator, int, int, int, int> {};
+  using AdaptedIter = iterator_adaptor_base<WeirdIter>;
+  static_assert(std::is_same<typename AdaptedIter::value_type, int>::value, "");
+  static_assert(std::is_same<typename AdaptedIter::difference_type, int>::value,
+                "");
+  static_assert(std::is_same<typename AdaptedIter::pointer, int>::value, "");
+  static_assert(std::is_same<typename AdaptedIter::reference, int>::value, "");
+}
+
 } // anonymous namespace
Index: include/llvm/ADT/iterator.h
===================================================================
--- include/llvm/ADT/iterator.h
+++ include/llvm/ADT/iterator.h
@@ -155,7 +155,14 @@
     typename T = typename std::iterator_traits<WrappedIteratorT>::value_type,
     typename DifferenceTypeT =
         typename std::iterator_traits<WrappedIteratorT>::difference_type,
-    typename PointerT = T *, typename ReferenceT = T &,
+    typename PointerT = typename std::conditional<
+        std::is_same<T, typename std::iterator_traits<
+                            WrappedIteratorT>::value_type>::value,
+        typename std::iterator_traits<WrappedIteratorT>::pointer, T *>::type,
+    typename ReferenceT = typename std::conditional<
+        std::is_same<T, typename std::iterator_traits<
+                            WrappedIteratorT>::value_type>::value,
+        typename std::iterator_traits<WrappedIteratorT>::reference, T &>::type,
     // Don't provide these, they are mostly to act as aliases below.
     typename WrappedTraitsT = std::iterator_traits<WrappedIteratorT>>
 class iterator_adaptor_base


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23217.66986.patch
Type: text/x-patch
Size: 1914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160805/0b9f8f68/attachment.bin>


More information about the llvm-commits mailing list