JSON for Modern C++  3.7.0

◆ empty()

template<typename BasicJsonType >
bool nlohmann::json_pointer< BasicJsonType >::empty ( ) const
inlinenoexcept
Returns
true iff the JSON pointer points to the root document
Complexity
Constant.
Exception safety
No-throw guarantee: this function never throws exceptions.
Example
The example shows the result of empty for different JSON Pointers.
1 #include <iostream>
2 #include <nlohmann/json.hpp>
3 
4 using json = nlohmann::json;
5 
6 int main()
7 {
8  // different JSON Pointers
10  json::json_pointer ptr1("");
11  json::json_pointer ptr2("/foo");
12  json::json_pointer ptr3("/foo/0");
13 
14  // call empty()
15  std::cout << std::boolalpha
16  << ptr0 << ": " << ptr0.empty() << '\n'
17  << ptr1 << ": " << ptr1.empty() << '\n'
18  << ptr2 << ": " << ptr2.empty() << '\n'
19  << ptr3 << ": " << ptr3.empty() << std::endl;
20 }
basic_json<> json
default JSON class
Definition: json.hpp:2355
::nlohmann::json_pointer< basic_json > json_pointer
JSON Pointer, see nlohmann::json_pointer.
Definition: json.hpp:14616

Output (play with this example online):
"": true
"": true
"/foo": false
"/foo/0": false
The example code above can be translated with
g++ -std=c++11 -Isingle_include doc/examples/json_pointer__empty.cpp -o json_pointer__empty 
Since
version 3.6.0

Definition at line 10279 of file json.hpp.