[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
Tue Aug 9 13:31:01 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL278157: [ADT] Change iterator_adaptor_base's default template arguments to forward… (authored by timshen).
Changed prior to commit:
https://reviews.llvm.org/D23217?vs=67402&id=67409#toc
Repository:
rL LLVM
https://reviews.llvm.org/D23217
Files:
llvm/trunk/include/llvm/ADT/iterator.h
llvm/trunk/unittests/Support/IteratorTest.cpp
Index: llvm/trunk/include/llvm/ADT/iterator.h
===================================================================
--- llvm/trunk/include/llvm/ADT/iterator.h
+++ llvm/trunk/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
Index: llvm/trunk/unittests/Support/IteratorTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/IteratorTest.cpp
+++ llvm/trunk/unittests/Support/IteratorTest.cpp
@@ -16,6 +16,24 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23217.67409.patch
Type: text/x-patch
Size: 2236 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160809/d8988a7a/attachment.bin>
More information about the llvm-commits
mailing list