Add missing erase(first, last) function to ordered_map (#3109)

This commit is contained in:
Niels Lohmann
2021-11-09 22:24:58 +01:00
committed by GitHub
parent 834918018e
commit e9f88c2fad
4 changed files with 148 additions and 14 deletions

View File

@@ -746,6 +746,23 @@ TEST_CASE("regression tests 2")
std::vector<FooBar> foo;
j.get_to(foo);
}
SECTION("issue #3108 - ordered_json doesn't support range based erase")
{
ordered_json j = {1, 2, 2, 4};
auto last = std::unique(j.begin(), j.end());
j.erase(last, j.end());
CHECK(j.dump() == "[1,2,4]");
j.erase(std::remove_if(j.begin(), j.end(), [](const ordered_json & val)
{
return val == 2;
}), j.end());
CHECK(j.dump() == "[1,4]");
}
}
DOCTEST_CLANG_SUPPRESS_WARNING_POP