llvm.org GIT mirror llvm / 1f1713f
Remove my bogus MapVector::erase() with a narrower ::pop_back(), and add a unit test. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175538 91177308-0d34-0410-b5e6-96231b3b80d8 Douglas Gregor 6 years ago
2 changed file(s) with 19 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
118118 (Vector.begin() + Pos->second);
119119 }
120120
121 /// \brief Erase entry with the given key.
122 void erase(const KeyT &key) {
123 typename MapType::iterator Pos = Map.find(key);
124 if (Pos == Map.end())
125 return;
126
127 Vector.erase(Vector.begin() + Pos->second);
121 /// \brief Remove the last element from the vector.
122 void pop_back() {
123 typename MapType::iterator Pos = Map.find(Vector.back().first);
128124 Map.erase(Pos);
125 Vector.pop_back();
129126 }
130127 };
131128
1212
1313 using namespace llvm;
1414
15 TEST(MapVectorTest, insert) {
15 TEST(MapVectorTest, insert_pop) {
1616 MapVector MV;
1717 std::pair::iterator, bool> R;
1818
3737 EXPECT_EQ(MV.size(), 2u);
3838 EXPECT_EQ(MV[1], 2);
3939 EXPECT_EQ(MV[4], 5);
40
41 MV.pop_back();
42 EXPECT_EQ(MV.size(), 1u);
43 EXPECT_EQ(MV[1], 2);
44
45 R = MV.insert(std::make_pair(4, 7));
46 ASSERT_NE(R.first, MV.end());
47 EXPECT_EQ(R.first->first, 4);
48 EXPECT_EQ(R.first->second, 7);
49 EXPECT_TRUE(R.second);
50
51 EXPECT_EQ(MV.size(), 2u);
52 EXPECT_EQ(MV[1], 2);
53 EXPECT_EQ(MV[4], 7);
4054 }