| 2251 | std::is_same<IteratorType, typename basic_json_t::const_iterator>::value, int >::type |
| 2252 | = 0 > |
| 2253 | IteratorType erase(IteratorType pos) |
| 2254 | { |
| 2255 | // make sure iterator fits the current value |
| 2256 | if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) |
| 2257 | { |
| 2258 | JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); |
| 2259 | } |
| 2260 | |
| 2261 | IteratorType result = end(); |
| 2262 | |
| 2263 | switch (m_type) |
| 2264 | { |
| 2265 | case value_t::boolean: |
| 2266 | case value_t::number_float: |
| 2267 | case value_t::number_integer: |
| 2268 | case value_t::number_unsigned: |
| 2269 | case value_t::string: |
| 2270 | case value_t::binary: |
| 2271 | { |
| 2272 | if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin())) |
| 2273 | { |
| 2274 | JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this)); |
| 2275 | } |
| 2276 | |
| 2277 | if (is_string()) |
| 2278 | { |
| 2279 | AllocatorType<string_t> alloc; |
| 2280 | std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.string); |
| 2281 | std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.string, 1); |
| 2282 | m_value.string = nullptr; |
| 2283 | } |
| 2284 | else if (is_binary()) |
| 2285 | { |
| 2286 | AllocatorType<binary_t> alloc; |
| 2287 | std::allocator_traits<decltype(alloc)>::destroy(alloc, m_value.binary); |
| 2288 | std::allocator_traits<decltype(alloc)>::deallocate(alloc, m_value.binary, 1); |
| 2289 | m_value.binary = nullptr; |
| 2290 | } |
| 2291 | |
| 2292 | m_type = value_t::null; |
| 2293 | assert_invariant(); |
| 2294 | break; |
| 2295 | } |
| 2296 | |
| 2297 | case value_t::object: |
| 2298 | { |
| 2299 | result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); |
| 2300 | break; |
| 2301 | } |
| 2302 | |
| 2303 | case value_t::array: |
| 2304 | { |
| 2305 | result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); |
| 2306 | break; |
| 2307 | } |
| 2308 | |
| 2309 | case value_t::null: |
| 2310 | case value_t::discarded: |
no test coverage detected