diff --git a/docs/mkdocs/docs/api/basic_json_document/erase.md b/docs/mkdocs/docs/api/basic_json_document/erase.md index cbdc79765..5f6b7fc0a 100644 --- a/docs/mkdocs/docs/api/basic_json_document/erase.md +++ b/docs/mkdocs/docs/api/basic_json_document/erase.md @@ -69,10 +69,10 @@ has `erase`; calling it on a read-only `basic_json_document` fails to compile (` [`out_of_range.404`](../../home/exceptions.md#jsonexceptionout_of_range404) (an empty token); otherwise (an object, or a primitive value the pointer's parent resolves to) throws what 1. throws. -Every overload also throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) ("view -does not belong to this document") if `object`/`array` is a [discarded](../basic_json_view/is_discarded.md) view or a -view of a *different* document (overloads 1-2 only; overload 3 always starts from this document's own -[`root()`](root.md)). +Overloads 1. and 2. also throw [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) +("view does not belong to this document") if `object`/`array` is a [discarded](../basic_json_view/is_discarded.md) +view or a view of a *different* document. Overload 3. takes no view: it always starts from this document's own +[`root()`](root.md). ## Complexity @@ -92,9 +92,10 @@ view of a *different* document (overloads 1-2 only; overload 3 always starts fro Like [`set`](set.md) and [`push_back`](push_back.md), `erase` never moves an element's *value*: a view still referring to a removed member or element keeps showing what it last held (see [Edits](index.md#edits)) -- it just no -longer appears when `array`/`object` is read, dumped, or iterated. Removing an element of `array` (2.) does shift the -*links* to the elements after it, the same way `insert`, `set`, or `push_back` on the same array would; any iterator -already taken over `array`/`object` is invalidated by an erase, since it was walking the old layout. +longer appears when `array`/`object` is read, dumped, or iterated. What does change is the container's sequence of +*links* to its elements: removing an element of `array` (2.) shifts the links to the elements after it by one, as +[`insert`](insert.md) does in the other direction. *Every* iterator already taken over `array`/`object` is invalidated +by an erase, not only those at or after the removed element, since the container may now use a different sequence. ## Examples diff --git a/include/nlohmann/detail/view/edit.hpp b/include/nlohmann/detail/view/edit.hpp index 57a3297b3..ec18793c9 100644 --- a/include/nlohmann/detail/view/edit.hpp +++ b/include/nlohmann/detail/view/edit.hpp @@ -12,7 +12,7 @@ #include // isinf, isnan #include // size_t #include // int64_t, uint8_t, uint32_t, uint64_t -#include // memcmp, memmove +#include // memmove #include // numeric_limits #include // string, to_string #include // decay, enable_if, integral_constant, is_arithmetic, is_convertible, is_floating_point, is_same, is_signed @@ -313,7 +313,7 @@ class editor bool key_equals(const node& k, string_view_t key) const noexcept { - return k.len == key.size() && (key.size() == 0 || std::memcmp(m_doc.str(k), key.data(), key.size()) == 0); + return m_doc.key_equals(k, key.data(), key.size()); } /// remove the members with this key (all, or all but the first) from an object