From 67f28904e3c37e31e6270ff0e65aa539f538c27a Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Thu, 18 Aug 2016 16:27:41 +0000 Subject: [PATCH] Revert "ADT: Remove references in has_rbegin for reverse()" This reverts commit r279084, since it failed on a bot: http://bb.pgr.jp/builders/cmake-llvm-x86_64-linux/builds/41733 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279086 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/STLExtras.h | 10 ++--- unittests/ADT/RangeAdapterTest.cpp | 66 ++---------------------------- 2 files changed, 7 insertions(+), 69 deletions(-) diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index eb515fd4583..8e4d186d15a 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -208,8 +208,9 @@ inline mapped_iterator map_iterator(const ItTy &I, FuncTy F) { return mapped_iterator(I, F); } -/// Helper to determine if type T has a member called rbegin(). -template class has_rbegin_impl { +/// \brief Metafunction to determine if type T has a member called rbegin(). +template +class has_rbegin { typedef char yes[1]; typedef char no[2]; @@ -223,11 +224,6 @@ public: static const bool value = sizeof(test(nullptr)) == sizeof(yes); }; -/// Metafunction to determine if T& or T has a member called rbegin(). -template -struct has_rbegin : has_rbegin_impl::type> { -}; - // Returns an iterator_range over the given container which iterates in reverse. // Note that the container must have rbegin()/rend() methods for this to work. template diff --git a/unittests/ADT/RangeAdapterTest.cpp b/unittests/ADT/RangeAdapterTest.cpp index d1a357190fc..2b12fe47173 100644 --- a/unittests/ADT/RangeAdapterTest.cpp +++ b/unittests/ADT/RangeAdapterTest.cpp @@ -75,50 +75,6 @@ public: const_reverse_iterator rend() const { return Vec.rend(); } }; -/// Check that types with custom iterators work. -class CustomIteratorVector { - mutable std::vector V; - -public: - CustomIteratorVector(std::initializer_list list) : V(list) {} - - typedef std::vector::iterator iterator; - class reverse_iterator { - std::vector::iterator I; - - public: - reverse_iterator() = default; - reverse_iterator(const reverse_iterator &) = default; - reverse_iterator &operator=(const reverse_iterator &) = default; - - explicit reverse_iterator(std::vector::iterator I) : I(I) {} - - reverse_iterator &operator++() { - --I; - return *this; - } - reverse_iterator &operator--() { - ++I; - return *this; - } - int &operator*() const { return *std::prev(I); } - int *operator->() const { return &*std::prev(I); } - friend bool operator==(const reverse_iterator &L, - const reverse_iterator &R) { - return L.I == R.I; - } - friend bool operator!=(const reverse_iterator &L, - const reverse_iterator &R) { - return !(L == R); - } - }; - - iterator begin() const { return V.begin(); } - iterator end() const { return V.end(); } - reverse_iterator rbegin() const { return reverse_iterator(V.end()); } - reverse_iterator rend() const { return reverse_iterator(V.begin()); } -}; - template void TestRev(const R &r) { int counter = 3; for (int i : r) @@ -142,10 +98,9 @@ TYPED_TEST(RangeAdapterLValueTest, TrivialOperation) { template struct RangeAdapterRValueTest : testing::Test {}; -typedef ::testing::Types, std::list, CustomIteratorVector, - ReverseOnlyVector, BidirectionalVector, - BidirectionalVectorConsts> - RangeAdapterRValueTestTypes; +typedef ::testing::Types, std::list, ReverseOnlyVector, + BidirectionalVector, + BidirectionalVectorConsts> RangeAdapterRValueTestTypes; TYPED_TEST_CASE(RangeAdapterRValueTest, RangeAdapterRValueTestTypes); TYPED_TEST(RangeAdapterRValueTest, TrivialOperation) { @@ -153,20 +108,7 @@ TYPED_TEST(RangeAdapterRValueTest, TrivialOperation) { } TYPED_TEST(RangeAdapterRValueTest, HasRbegin) { - static_assert(has_rbegin::value, "rbegin() should be defined"); -} - -TYPED_TEST(RangeAdapterRValueTest, RangeType) { - static_assert( - std::is_same< - decltype(reverse(*static_cast(nullptr)).begin()), - decltype(static_cast(nullptr)->rbegin())>::value, - "reverse().begin() should have the same type as rbegin()"); - static_assert( - std::is_same< - decltype(reverse(*static_cast(nullptr)).begin()), - decltype(static_cast(nullptr)->rbegin())>::value, - "reverse().begin() should have the same type as rbegin() [const]"); + EXPECT_TRUE(has_rbegin::value); } } // anonymous namespace