forked from organicmaps/organicmaps
[base] Add erase method to buffer_vector.
This commit is contained in:
parent
c1c7d3abe8
commit
1eb4e77239
2 changed files with 34 additions and 0 deletions
|
@ -363,3 +363,24 @@ UNIT_TEST(BufferVector_OnlyMoveableItems)
|
|||
for (size_t i = 0; i < 10; ++i)
|
||||
TEST_EQUAL(*v[i], i, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(BufferVector_Erase)
|
||||
{
|
||||
buffer_vector<int, 32> v1;
|
||||
std::vector<int> v2;
|
||||
for (int i = 1; i < 100; ++i)
|
||||
{
|
||||
v1.push_back(i);
|
||||
v2.push_back(i);
|
||||
}
|
||||
|
||||
while (v1.size() > 1)
|
||||
{
|
||||
v1.erase(v1.begin() + v1.size() / 3, v1.begin() + 2 * v1.size () / 3);
|
||||
v2.erase(v2.begin() + v2.size() / 3, v2.begin() + 2 * v2.size () / 3);
|
||||
|
||||
TEST_EQUAL(v1.size(), v2.size(), ());
|
||||
for (size_t i = 0; i < v1.size(); ++i)
|
||||
TEST_EQUAL(v1[i], v2[i], ());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -410,6 +410,19 @@ public:
|
|||
resize(std::distance(b, i));
|
||||
}
|
||||
|
||||
void erase(iterator first, iterator last)
|
||||
{
|
||||
if (first == last)
|
||||
return;
|
||||
|
||||
auto const numToErase = std::distance(first, last);
|
||||
for (; first != end() - numToErase; ++first)
|
||||
{
|
||||
Swap(*first, *(first + numToErase));
|
||||
}
|
||||
resize(std::distance(begin(), first));
|
||||
}
|
||||
|
||||
private:
|
||||
void SwitchToDynamic()
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue