From 2962e3e6b2f5ce87c28631353dfecd564531c5f8 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Tue, 9 Aug 2016 20:23:13 +0000 Subject: [PATCH] [ADT] Change iterator_adaptor_base's default template arguments to forward more underlying typedefs Reviewers: chandlerc Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D23217 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@278157 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/iterator.h | 9 ++++++++- unittests/Support/IteratorTest.cpp | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/llvm/ADT/iterator.h b/include/llvm/ADT/iterator.h index 2898a677db3..14830d06c2a 100644 --- a/include/llvm/ADT/iterator.h +++ b/include/llvm/ADT/iterator.h @@ -155,7 +155,14 @@ template < typename T = typename std::iterator_traits::value_type, typename DifferenceTypeT = typename std::iterator_traits::difference_type, - typename PointerT = T *, typename ReferenceT = T &, + typename PointerT = typename std::conditional< + std::is_same::value_type>::value, + typename std::iterator_traits::pointer, T *>::type, + typename ReferenceT = typename std::conditional< + std::is_same::value_type>::value, + typename std::iterator_traits::reference, T &>::type, // Don't provide these, they are mostly to act as aliases below. typename WrappedTraitsT = std::iterator_traits> class iterator_adaptor_base diff --git a/unittests/Support/IteratorTest.cpp b/unittests/Support/IteratorTest.cpp index 83848328c0c..853d16cef46 100644 --- a/unittests/Support/IteratorTest.cpp +++ b/unittests/Support/IteratorTest.cpp @@ -16,6 +16,24 @@ using namespace llvm; namespace { +template struct Shadow; + +struct WeirdIter : std::iterator, Shadow<1>, + Shadow<2>, Shadow<3>> {}; + +struct AdaptedIter : iterator_adaptor_base {}; + +// Test that iterator_adaptor_base forwards typedefs, if value_type is +// unchanged. +static_assert(std::is_same>::value, + ""); +static_assert( + std::is_same>::value, ""); +static_assert(std::is_same>::value, + ""); +static_assert(std::is_same>::value, + ""); + TEST(PointeeIteratorTest, Basic) { int arr[4] = { 1, 2, 3, 4 }; SmallVector V;