From fa3b196773082e4c27e18d988467cd628b22ee6d Mon Sep 17 00:00:00 2001 From: Niels Date: Sat, 11 Apr 2015 16:37:43 +0200 Subject: [PATCH] Created nlohmann::basicjson::erase (markdown) --- nlohmann::basicjson::erase.md | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 nlohmann::basicjson::erase.md diff --git a/nlohmann::basicjson::erase.md b/nlohmann::basicjson::erase.md new file mode 100644 index 0000000..80a3104 --- /dev/null +++ b/nlohmann::basicjson::erase.md @@ -0,0 +1,57 @@ +```cpp +iterator erase(iterator pos); +const_iterator erase(const_iterator pos); // 1 +``` +```cpp +iterator erase(iterator first, iterator last); +const_iterator erase(const_iterator first, const_iterator last); // 2 +``` +```cpp +void erase(const size_type idx); // 3 +``` +```cpp +size_type erase(const typename object_t::key_type& key); // 4 +``` + +## Description + +Removes specified elements from the JSON value. + +1. Removes the element at `pos`. +2. Removes the elements in the range [`first`; `last`). +3. Removes the element at index `idx` (only works for arrays). +4. Removes the element with key `key` (only works for objects). + +Invalidates iterators and references at or after the point of the erase, including the `end()` iterator. + +The iterator `pos` must be valid and dereferenceable. Thus the `end()` iterator (which is valid, but is not dereferencable) cannot be used as a value for `pos`. + +The iterator `first` does not need to be dereferenceable if `first==last`: erasing an empty range is a no-op. + +## Parameter + +- `pos`: iterator to the element to remove +- `first`, `last`: range of elements to remove +- `idx`: index of the element to remove +- `key`: key of the element to remove + +## Return value + +1. Iterator following the last removed element. If the iterator pos refers to the last element, the `end()` iterator is returned. +2. Iterator following the last removed element. If the iterator pos refers to the last element, the `end()` iterator is returned. +3. None. +4. Number of elements removed. + +## Complexity + +1. Linear in distance between `pos` and the end of the container in case of arrays; amortized constant in case of objects; constant otherwise. +2. Linear in the distance between `first` and `last`, plus linear in the distance between `last` and end of the container in case of arrays; `log(c.size()) + std::distance(first, last)` where `c` is the instance of `ObjectType` in case of objects; constant otherwise. +3. Linear in distance between `idx` and the end of the container. +4. `log(c.size()) + c.count(key)` where `c` is the instance of `ObjectType`. + +## Exceptions + +1. `std::runtime_error` when called on null type. +2. `std::runtime_error` when called on null type. +3. `std::runtime_error` when called on non-array types. `std::out_of_range` when `idx >= size()`. +4. `std::runtime_error` when called on non-object types. Any exceptions thrown by the `ObjectType::Compare` object. \ No newline at end of file