added documentation for erase functions
This commit is contained in:
parent
862e7000f4
commit
7d9cfb1b32
10 changed files with 327 additions and 34 deletions
30
doc/examples/erase__IteratorType.cpp
Normal file
30
doc/examples/erase__IteratorType.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create JSON values
|
||||
json j_boolean = true;
|
||||
json j_number_integer = 17;
|
||||
json j_number_float = 23.42;
|
||||
json j_object = {{"one", 1}, {"two", 2}};
|
||||
json j_array = {1, 2, 4, 8, 16};
|
||||
json j_string = "Hello, world";
|
||||
|
||||
// call erase
|
||||
j_boolean.erase(j_boolean.begin());
|
||||
j_number_integer.erase(j_number_integer.begin());
|
||||
j_number_float.erase(j_number_float.begin());
|
||||
j_object.erase(j_object.find("two"));
|
||||
j_array.erase(j_array.begin() + 2);
|
||||
j_string.erase(j_string.begin());
|
||||
|
||||
// print values
|
||||
std::cout << j_boolean << '\n';
|
||||
std::cout << j_number_integer << '\n';
|
||||
std::cout << j_number_float << '\n';
|
||||
std::cout << j_object << '\n';
|
||||
std::cout << j_array << '\n';
|
||||
std::cout << j_string << '\n';
|
||||
}
|
6
doc/examples/erase__IteratorType.output
Normal file
6
doc/examples/erase__IteratorType.output
Normal file
|
@ -0,0 +1,6 @@
|
|||
null
|
||||
null
|
||||
null
|
||||
{"one":1}
|
||||
[1,2,8,16]
|
||||
null
|
30
doc/examples/erase__IteratorType_IteratorType.cpp
Normal file
30
doc/examples/erase__IteratorType_IteratorType.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create JSON values
|
||||
json j_boolean = true;
|
||||
json j_number_integer = 17;
|
||||
json j_number_float = 23.42;
|
||||
json j_object = {{"one", 1}, {"two", 2}};
|
||||
json j_array = {1, 2, 4, 8, 16};
|
||||
json j_string = "Hello, world";
|
||||
|
||||
// call erase
|
||||
j_boolean.erase(j_boolean.begin(), j_boolean.end());
|
||||
j_number_integer.erase(j_number_integer.begin(), j_number_integer.end());
|
||||
j_number_float.erase(j_number_float.begin(), j_number_float.end());
|
||||
j_object.erase(j_object.find("two"), j_object.end());
|
||||
j_array.erase(j_array.begin() + 1, j_array.begin() + 3);
|
||||
j_string.erase(j_string.begin(), j_string.end());
|
||||
|
||||
// print values
|
||||
std::cout << j_boolean << '\n';
|
||||
std::cout << j_number_integer << '\n';
|
||||
std::cout << j_number_float << '\n';
|
||||
std::cout << j_object << '\n';
|
||||
std::cout << j_array << '\n';
|
||||
std::cout << j_string << '\n';
|
||||
}
|
6
doc/examples/erase__IteratorType_IteratorType.output
Normal file
6
doc/examples/erase__IteratorType_IteratorType.output
Normal file
|
@ -0,0 +1,6 @@
|
|||
null
|
||||
null
|
||||
null
|
||||
{"one":1}
|
||||
[1,8,16]
|
||||
null
|
17
doc/examples/erase__key_type.cpp
Normal file
17
doc/examples/erase__key_type.cpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON object
|
||||
json j_object = {{"one", 1}, {"two", 2}};
|
||||
|
||||
// call erase
|
||||
auto count_one = j_object.erase("one");
|
||||
auto count_three = j_object.erase("three");
|
||||
|
||||
// print values
|
||||
std::cout << j_object << '\n';
|
||||
std::cout << count_one << " " << count_three << '\n';
|
||||
}
|
2
doc/examples/erase__key_type.output
Normal file
2
doc/examples/erase__key_type.output
Normal file
|
@ -0,0 +1,2 @@
|
|||
{"two":2}
|
||||
1 0
|
15
doc/examples/erase__size_type.cpp
Normal file
15
doc/examples/erase__size_type.cpp
Normal file
|
@ -0,0 +1,15 @@
|
|||
#include <json.hpp>
|
||||
|
||||
using namespace nlohmann;
|
||||
|
||||
int main()
|
||||
{
|
||||
// create a JSON array
|
||||
json j_array = {0, 1, 2, 3, 4, 5};
|
||||
|
||||
// call erase
|
||||
j_array.erase(2);
|
||||
|
||||
// print values
|
||||
std::cout << j_array << '\n';
|
||||
}
|
1
doc/examples/erase__size_type.output
Normal file
1
doc/examples/erase__size_type.output
Normal file
|
@ -0,0 +1 @@
|
|||
[0,1,3,4,5]
|
Loading…
Add table
Add a link
Reference in a new issue