template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::erase |
( |
const size_type |
idx | ) |
|
|
inline |
remove element from a JSON array given an index
Removes element from a JSON array at the index idx.
- Parameters
-
[in] | idx | index of the element to remove |
- Exceptions
-
type_error.307 | when called on a type other than JSON object; example: "cannot use erase() with null" |
out_of_range.401 | when idx >= size() ; example: "array index 17
is out of range" |
@complexity Linear in distance between idx and the end of the container.
@liveexample{The example shows the effect of erase()
.,erase__size_type}
- See also
- see erase(IteratorType) – removes the element at a given position
-
see erase(IteratorType, IteratorType) – removes the elements in the given range
-
see erase(const typename object_t::key_type&) – removes the element from an object at the given key
- Since
- version 1.0.0
Definition at line 22169 of file json.hpp.
22170 {
22171
22172 if (JSON_HEDLEY_LIKELY(
is_array()))
22173 {
22174 if (JSON_HEDLEY_UNLIKELY(idx >=
size()))
22175 {
22176 JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this));
22177 }
22178
22180 }
22181
22182 else
22183 {
22184 JSON_THROW(type_error::create(307,
"cannot use erase() with " + std::string(
type_name()), *
this));
22185 }
22186 }
size_type size() const noexcept
returns the number of elements
std::ptrdiff_t difference_type
a type to represent differences between iterators
json_value m_value
the value of the current element
constexpr bool is_array() const noexcept
return whether value is an array
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string