Re-implement ordered_map::erase,

so that it can handle pair<const Key,...>
This commit is contained in:
gatopeich committed 2020-06-23 15:01:20 +01:00
1 parent acd748e16f
commit fb8c11f25c
3 files changed
+22 -8

No files matched your search

+3 -3
View File
@@ -499,9 +499,9 @@ class basic_json
// Note the use of std::map default allocator as a placeholder // Note the use of std::map default allocator as a placeholder
// to extract the actual ObjectType::value_type // to extract the actual ObjectType::value_type
AllocatorType<typename AllocatorType<typename
ObjectType<StringType,basic_json,object_comparator_t, ObjectType<StringType, basic_json, object_comparator_t,
std::allocator<std::pair<const StringType, basic_json>> std::allocator<std::pair<const StringType, basic_json>>
>::value_type>>; >::value_type>>;
/*! /*!
@brief a type for an array @brief a type for an array
+8 -1
View File
@@ -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;
} }
} }
+11 -4
View File
@@ -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;
} }
} }
@@ -16351,9 +16358,9 @@ class basic_json
// Note the use of std::map default allocator as a placeholder // Note the use of std::map default allocator as a placeholder
// to extract the actual ObjectType::value_type // to extract the actual ObjectType::value_type
AllocatorType<typename AllocatorType<typename
ObjectType<StringType,basic_json,object_comparator_t, ObjectType<StringType, basic_json, object_comparator_t,
std::allocator<std::pair<const StringType, basic_json>> std::allocator<std::pair<const StringType, basic_json>>
>::value_type>>; >::value_type>>;
/*! /*!
@brief a type for an array @brief a type for an array