diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index 0605e522d7e..b68345a1dcf 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/include/llvm/ADT/STLExtras.h @@ -196,30 +196,6 @@ inline mapped_iterator map_iterator(const ItTy &I, FuncTy F) { return mapped_iterator(I, F); } -// 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 -auto reverse(ContainerTy &C)->decltype(make_range(C.rbegin(), C.rend())) { - return make_range(C.rbegin(), C.rend()); -} - -// Returns a std::reverse_iterator wrapped around the given iterator. -template -std::reverse_iterator make_reverse_iterator(IteratorTy It) { - return std::reverse_iterator(It); -} - -// Returns an iterator_range over the given container which iterates in reverse. -// Note that the container must have begin()/end() methods which return -// bidirectional iterators for this to work. -template -auto reverse(ContainerTy &&C) - ->decltype(make_range(make_reverse_iterator(std::end(C)), - make_reverse_iterator(std::begin(C)))) { - return make_range(make_reverse_iterator(std::end(C)), - make_reverse_iterator(std::begin(C))); -} - //===----------------------------------------------------------------------===// // Extra additions to //===----------------------------------------------------------------------===// diff --git a/lib/CodeGen/AsmPrinter/ARMException.cpp b/lib/CodeGen/AsmPrinter/ARMException.cpp index 462e5d19c8d..5f91763f27b 100644 --- a/lib/CodeGen/AsmPrinter/ARMException.cpp +++ b/lib/CodeGen/AsmPrinter/ARMException.cpp @@ -115,7 +115,8 @@ void ARMException::emitTypeInfos(unsigned TTypeEncoding) { Entry = TypeInfos.size(); } - for (const GlobalValue *GV : reverse(TypeInfos)) { + for (const GlobalValue *GV : make_range(TypeInfos.rbegin(), + TypeInfos.rend())) { if (VerboseAsm) Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--)); Asm->EmitTTypeReference(GV, TTypeEncoding); diff --git a/unittests/ADT/CMakeLists.txt b/unittests/ADT/CMakeLists.txt index cb878c61b85..cbcb0848556 100644 --- a/unittests/ADT/CMakeLists.txt +++ b/unittests/ADT/CMakeLists.txt @@ -28,7 +28,6 @@ set(ADTSources PointerIntPairTest.cpp PointerUnionTest.cpp PostOrderIteratorTest.cpp - RangeAdapterTest.cpp SCCIteratorTest.cpp SmallPtrSetTest.cpp SmallStringTest.cpp diff --git a/unittests/ADT/RangeAdapterTest.cpp b/unittests/ADT/RangeAdapterTest.cpp deleted file mode 100644 index 7547f84ce49..00000000000 --- a/unittests/ADT/RangeAdapterTest.cpp +++ /dev/null @@ -1,77 +0,0 @@ -//===- RangeAdapterTest.cpp - Unit tests for range adapters --------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "llvm/ADT/iterator_range.h" -#include "llvm/ADT/STLExtras.h" -#include "gtest/gtest.h" - -#include -#include -#include - -using namespace llvm; - -namespace { - -// A wrapper around vector which exposes rbegin(), rend(). -class ReverseOnlyVector { - std::vector Vec; -public: - ReverseOnlyVector(std::initializer_list list) : Vec(list) { } - - typedef std::vector::reverse_iterator reverse_iterator; - reverse_iterator rbegin() { return Vec.rbegin(); } - reverse_iterator rend() { return Vec.rend(); } -}; - -// A wrapper around vector which exposes begin(), end(), rbegin() and rend(). -// begin() and end() don't have implementations as this ensures that we will -// get a linker error if reverse() chooses begin()/end() over rbegin(), rend(). -class BidirectionalVector { - std::vector Vec; - -public: - BidirectionalVector(std::initializer_list list) : Vec(list) { } - - typedef std::vector::iterator iterator; - iterator begin(); - iterator end(); - - typedef std::vector::reverse_iterator reverse_iterator; - reverse_iterator rbegin() { return Vec.rbegin(); } - reverse_iterator rend() { return Vec.rend(); } -}; - -// Test fixture -template -class RangeAdapterTest : public ::testing::Test { }; - -typedef ::testing::Types, - std::list, - int[4], - ReverseOnlyVector, - BidirectionalVector, - const std::vector, - const std::list, - const int[4]> RangeAdapterTestTypes; -TYPED_TEST_CASE(RangeAdapterTest, RangeAdapterTestTypes); - -TYPED_TEST(RangeAdapterTest, TrivialOperation) { - TypeParam v = { 0, 1, 2, 3 }; - - int counter = 3; - for (int i : reverse(v)) - EXPECT_EQ(i, counter--); - - counter = 0; - for (int i : reverse(reverse(v))) - EXPECT_EQ(i, counter++); -} - -} // anonymous namespace