Commit eab8d3c3 authored by Qinfan Wu's avatar Qinfan Wu Committed by Facebook Github Bot

Fix sorted_vector_set::erase

Summary: It deletes things even when input isn't in the container.

Reviewed By: luciang

Differential Revision: D4298340

fbshipit-source-id: 3e8fc04c2c21eb231dcaf82239ac5f6d25e49e2c
parent 65fc07b5
...@@ -281,7 +281,7 @@ public: ...@@ -281,7 +281,7 @@ public:
} }
size_type erase(const key_type& key) { size_type erase(const key_type& key) {
iterator it = lower_bound(key); iterator it = find(key);
if (it == end()) { if (it == end()) {
return 0; return 0;
} }
......
...@@ -339,3 +339,11 @@ TEST(SortedVectorTest, ShrinkTest) { ...@@ -339,3 +339,11 @@ TEST(SortedVectorTest, ShrinkTest) {
// vector::shrink_to_fit respects the caller. // vector::shrink_to_fit respects the caller.
EXPECT_EQ(s.capacity(), s.size()); EXPECT_EQ(s.capacity(), s.size());
} }
TEST(SortedVectorTypes, EraseTest) {
sorted_vector_set<int> s1;
s1.insert(1);
sorted_vector_set<int> s2(s1);
EXPECT_EQ(0, s1.erase(0));
EXPECT_EQ(s2, s1);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment