[llvm] r278157 - [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
Tue Aug 9 13:23:13 PDT 2016
Author: timshen
Date: Tue Aug 9 15:23:13 2016
New Revision: 278157
URL: http://llvm.org/viewvc/llvm-project?rev=278157&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/ADT/iterator.h
llvm/trunk/unittests/Support/IteratorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/iterator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/iterator.h?rev=278157&r1=278156&r2=278157&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/iterator.h (original)
+++ llvm/trunk/include/llvm/ADT/iterator.h Tue Aug 9 15:23:13 2016
@@ -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
Modified: llvm/trunk/unittests/Support/IteratorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/IteratorTest.cpp?rev=278157&r1=278156&r2=278157&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/IteratorTest.cpp (original)
+++ llvm/trunk/unittests/Support/IteratorTest.cpp Tue Aug 9 15:23:13 2016
@@ -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;
More information about the llvm-commits
mailing list