TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ erase() [1/4]

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]idxindex of the element to remove
Exceptions
type_error.307when called on a type other than JSON object; example: "cannot use erase() with null"
out_of_range.401when 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 // this erase only works for arrays
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
22179 m_value.array->erase(m_value.array->begin() + static_cast<difference_type>(idx));
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
Definition: json.hpp:22912
std::ptrdiff_t difference_type
a type to represent differences between iterators
Definition: json.hpp:17978
json_value m_value
the value of the current element
Definition: json.hpp:24928
constexpr bool is_array() const noexcept
return whether value is an array
Definition: json.hpp:20432
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
Definition: json.hpp:24883