xref: /third_party/json/docs/examples/get_ptr.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
3c5f01b2fSopenharmony_ci
4c5f01b2fSopenharmony_ciusing json = nlohmann::json;
5c5f01b2fSopenharmony_ci
6c5f01b2fSopenharmony_ciint main()
7c5f01b2fSopenharmony_ci{
8c5f01b2fSopenharmony_ci    // create a JSON number
9c5f01b2fSopenharmony_ci    json value = 17;
10c5f01b2fSopenharmony_ci
11c5f01b2fSopenharmony_ci    // explicitly getting pointers
12c5f01b2fSopenharmony_ci    auto p1 = value.get_ptr<const json::number_integer_t*>();
13c5f01b2fSopenharmony_ci    auto p2 = value.get_ptr<json::number_integer_t*>();
14c5f01b2fSopenharmony_ci    auto p3 = value.get_ptr<json::number_integer_t* const>();
15c5f01b2fSopenharmony_ci    auto p4 = value.get_ptr<const json::number_integer_t* const>();
16c5f01b2fSopenharmony_ci    auto p5 = value.get_ptr<json::number_float_t*>();
17c5f01b2fSopenharmony_ci
18c5f01b2fSopenharmony_ci    // print the pointees
19c5f01b2fSopenharmony_ci    std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
20c5f01b2fSopenharmony_ci    std::cout << std::boolalpha << (p5 == nullptr) << '\n';
21c5f01b2fSopenharmony_ci}
22

Indexes created Thu Nov 07 10:32:03 CST 2024