Skip to content

Commit

Permalink
Add MapVector::rbegin(), MapVector::rend() to completment MapVector::…
Browse files Browse the repository at this point in the history
…begin(), MapVector::end().

These just delegate to the underlying vector type in the MapVector.

Also just add in some sanity unittests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220687 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gottesmm committed Oct 27, 2014
1 parent af628cc commit 86ec9c4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
28 changes: 11 additions & 17 deletions include/llvm/ADT/MapVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,20 @@ class MapVector {
public:
typedef typename VectorType::iterator iterator;
typedef typename VectorType::const_iterator const_iterator;
typedef typename VectorType::reverse_iterator reverse_iterator;
typedef typename VectorType::const_reverse_iterator const_reverse_iterator;

size_type size() const {
return Vector.size();
}

iterator begin() {
return Vector.begin();
}
size_type size() const { return Vector.size(); }

const_iterator begin() const {
return Vector.begin();
}
iterator begin() { return Vector.begin(); }
const_iterator begin() const { return Vector.begin(); }
iterator end() { return Vector.end(); }
const_iterator end() const { return Vector.end(); }

iterator end() {
return Vector.end();
}

const_iterator end() const {
return Vector.end();
}
reverse_iterator rbegin() { return Vector.rbegin(); }
const_reverse_iterator rbegin() const { return Vector.rbegin(); }
reverse_iterator rend() { return Vector.rend(); }
const_reverse_iterator rend() const { return Vector.rend(); }

bool empty() const {
return Vector.empty();
Expand Down
25 changes: 25 additions & 0 deletions unittests/ADT/MapVectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "gtest/gtest.h"
#include "llvm/ADT/MapVector.h"
#include "llvm/ADT/iterator_range.h"
#include <utility>

using namespace llvm;
Expand Down Expand Up @@ -97,3 +98,27 @@ TEST(MapVectorTest, remove_if) {
ASSERT_EQ(MV[4], 14);
ASSERT_EQ(MV[6], 16);
}

TEST(MapVectorTest, iteration_test) {
MapVector<int, int> MV;

MV.insert(std::make_pair(1, 11));
MV.insert(std::make_pair(2, 12));
MV.insert(std::make_pair(3, 13));
MV.insert(std::make_pair(4, 14));
MV.insert(std::make_pair(5, 15));
MV.insert(std::make_pair(6, 16));
ASSERT_EQ(MV.size(), 6u);

int count = 1;
for (auto P : make_range(MV.begin(), MV.end())) {
ASSERT_EQ(P.first, count);
count++;
}

count = 6;
for (auto P : make_range(MV.rbegin(), MV.rend())) {
ASSERT_EQ(P.first, count);
count--;
}
}

0 comments on commit 86ec9c4

Please sign in to comment.