mirror of
https://github.com/nlohmann/json.git
synced 2025-08-06 07:02:42 +03:00
Re-implement ordered_map::erase,
so that it can handle pair<const Key,...>
This commit is contained in:
@@ -46,7 +46,14 @@ struct ordered_map : Container
|
|||||||
{
|
{
|
||||||
if (it->first == key)
|
if (it->first == key)
|
||||||
{
|
{
|
||||||
Container::erase(it);
|
// Since we cannot move const Keys, re-construct them in place
|
||||||
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
|
{
|
||||||
|
// *it = std::move(*next); // deleted
|
||||||
|
it->~value_type(); // Destroy but keep allocation
|
||||||
|
new (&*it) value_type{std::move(*next)};
|
||||||
|
}
|
||||||
|
Container::pop_back();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15915,7 +15915,14 @@ struct ordered_map : Container
|
|||||||
{
|
{
|
||||||
if (it->first == key)
|
if (it->first == key)
|
||||||
{
|
{
|
||||||
Container::erase(it);
|
// Since we cannot move const Keys, re-construct them in place
|
||||||
|
for (auto next = it; ++next != this->end(); ++it)
|
||||||
|
{
|
||||||
|
// *it = std::move(*next); // deleted
|
||||||
|
it->~value_type(); // Destroy but keep allocation
|
||||||
|
new (&*it) value_type{std::move(*next)};
|
||||||
|
}
|
||||||
|
Container::pop_back();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user