summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Shen <timshen91@gmail.com>2016-08-09 20:23:13 +0000
committerTim Shen <timshen91@gmail.com>2016-08-09 20:23:13 +0000
commit75c1656afb3dc405dc7eb2cb7a2dc807fc2c9a85 (patch)
treea51f688920289b685a10cdc198a54db00afe83b9
parent0c7496718623caaf71c4ff6b9354891fcabca07f (diff)
downloadbcm5719-llvm-75c1656afb3dc405dc7eb2cb7a2dc807fc2c9a85.tar.gz
bcm5719-llvm-75c1656afb3dc405dc7eb2cb7a2dc807fc2c9a85.zip
[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 llvm-svn: 278157
-rw-r--r--llvm/include/llvm/ADT/iterator.h9
-rw-r--r--llvm/unittests/Support/IteratorTest.cpp18
2 files changed, 26 insertions, 1 deletions
diff --git a/llvm/include/llvm/ADT/iterator.h b/llvm/include/llvm/ADT/iterator.h
index 2898a677db3..14830d06c2a 100644
--- a/llvm/include/llvm/ADT/iterator.h
+++ b/llvm/include/llvm/ADT/iterator.h
@@ -155,7 +155,14 @@ template <
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
diff --git a/llvm/unittests/Support/IteratorTest.cpp b/llvm/unittests/Support/IteratorTest.cpp
index 83848328c0c..853d16cef46 100644
--- a/llvm/unittests/Support/IteratorTest.cpp
+++ b/llvm/unittests/Support/IteratorTest.cpp
@@ -16,6 +16,24 @@ using namespace llvm;
namespace {
+template <int> struct Shadow;
+
+struct WeirdIter : std::iterator<std::input_iterator_tag, Shadow<0>, Shadow<1>,
+ Shadow<2>, Shadow<3>> {};
+
+struct AdaptedIter : iterator_adaptor_base<AdaptedIter, WeirdIter> {};
+
+// Test that iterator_adaptor_base forwards typedefs, if value_type is
+// unchanged.
+static_assert(std::is_same<typename AdaptedIter::value_type, Shadow<0>>::value,
+ "");
+static_assert(
+ std::is_same<typename AdaptedIter::difference_type, Shadow<1>>::value, "");
+static_assert(std::is_same<typename AdaptedIter::pointer, Shadow<2>>::value,
+ "");
+static_assert(std::is_same<typename AdaptedIter::reference, Shadow<3>>::value,
+ "");
+
TEST(PointeeIteratorTest, Basic) {
int arr[4] = { 1, 2, 3, 4 };
SmallVector<int *, 4> V;
OpenPOWER on IntegriCloud