[llvm] r220687 - Add MapVector::rbegin(), MapVector::rend() to completment MapVector::begin(), MapVector::end().
Michael Gottesman
mgottesman at apple.com
Mon Oct 27 10:20:54 PDT 2014
Author: mgottesman
Date: Mon Oct 27 12:20:53 2014
New Revision: 220687
URL: http://llvm.org/viewvc/llvm-project?rev=220687&view=rev
Log:
Add MapVector::rbegin(), MapVector::rend() to completment MapVector::begin(), MapVector::end().
These just delegate to the underlying vector type in the MapVector.
Also just add in some sanity unittests.
Modified:
llvm/trunk/include/llvm/ADT/MapVector.h
llvm/trunk/unittests/ADT/MapVectorTest.cpp
Modified: llvm/trunk/include/llvm/ADT/MapVector.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/MapVector.h?rev=220687&r1=220686&r2=220687&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/MapVector.h (original)
+++ llvm/trunk/include/llvm/ADT/MapVector.h Mon Oct 27 12:20:53 2014
@@ -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();
- }
+ size_type size() const { return Vector.size(); }
- 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 begin() { return Vector.begin(); }
+ const_iterator begin() const { return Vector.begin(); }
+ 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();
Modified: llvm/trunk/unittests/ADT/MapVectorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/MapVectorTest.cpp?rev=220687&r1=220686&r2=220687&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/MapVectorTest.cpp (original)
+++ llvm/trunk/unittests/ADT/MapVectorTest.cpp Mon Oct 27 12:20:53 2014
@@ -9,6 +9,7 @@
#include "gtest/gtest.h"
#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/iterator_range.h"
#include <utility>
using namespace llvm;
@@ -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--;
+ }
+}
More information about the llvm-commits
mailing list