diff options
| author | Michael Gottesman <mgottesman@apple.com> | 2014-10-27 17:20:53 +0000 |
|---|---|---|
| committer | Michael Gottesman <mgottesman@apple.com> | 2014-10-27 17:20:53 +0000 |
| commit | d71825c3cbdb173274c2e3afcef2c66552400648 (patch) | |
| tree | 981555ff6654d73164e38e4998f934b77c47bd40 /llvm | |
| parent | e068ac77a223588faf7d80b36e516a656d9b52f6 (diff) | |
| download | bcm5719-llvm-d71825c3cbdb173274c2e3afcef2c66552400648.tar.gz bcm5719-llvm-d71825c3cbdb173274c2e3afcef2c66552400648.zip | |
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.
llvm-svn: 220687
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/include/llvm/ADT/MapVector.h | 28 | ||||
| -rw-r--r-- | llvm/unittests/ADT/MapVectorTest.cpp | 25 |
2 files changed, 36 insertions, 17 deletions
diff --git a/llvm/include/llvm/ADT/MapVector.h b/llvm/include/llvm/ADT/MapVector.h index d82c5799f44..14c49c5bf4b 100644 --- a/llvm/include/llvm/ADT/MapVector.h +++ b/llvm/include/llvm/ADT/MapVector.h @@ -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(); diff --git a/llvm/unittests/ADT/MapVectorTest.cpp b/llvm/unittests/ADT/MapVectorTest.cpp index 46cd36acea9..89197993467 100644 --- a/llvm/unittests/ADT/MapVectorTest.cpp +++ b/llvm/unittests/ADT/MapVectorTest.cpp @@ -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--; + } +} |

