xref: /third_party/json/docs/examples/cend.cpp (revision c5f01b2f)
1#include <iostream>
2#include <nlohmann/json.hpp>
3
4using json = nlohmann::json;
5
6int main()
7{
8    // create an array value
9    json array = {1, 2, 3, 4, 5};
10
11    // get an iterator to one past the last element
12    json::const_iterator it = array.cend();
13
14    // decrement the iterator to point to the last element
15    --it;
16
17    // serialize the element that the iterator points to
18    std::cout << *it << '\n';
19}
20