JSON for Modern C++  3.0
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 = int64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator>
void nlohmann::basic_json::erase ( const size_type  idx)
inline

Removes element from a JSON array at the index idx.

Parameters
[in]idxindex of the element to remove
Exceptions
std::domain_errorwhen called on a type other than JSON array
std::out_of_rangewhen idx >= size()
Complexity
Linear in distance between idx and the end of the container.
Example
The example shows the effect of erase.
1 #include <json.hpp>
2 
3 using namespace nlohmann;
4 
5 int main()
6 {
7  // create a JSON array
8  json j_array = {0, 1, 2, 3, 4, 5};
9 
10  // call erase
11  j_array.erase(2);
12 
13  // print values
14  std::cout << j_array << '\n';
15 }
a class to store JSON values
Definition: json.hpp:130
namespace for Niels Lohmann
Definition: json.hpp:55
InteratorType erase(InteratorType pos)
remove element given an iterator
Definition: json.hpp:2831
Output (play with this example online):
[0,1,3,4,5]
The example code above can be translated with
g++ -std=c++11 -Isrc doc/examples/erase__size_type.cpp -o erase__size_type