get_ptr.cpp 641 B

123456789101112131415161718192021
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create a JSON number
  7. json value = 17;
  8. // explicitly getting pointers
  9. auto p1 = value.get_ptr<const json::number_integer_t*>();
  10. auto p2 = value.get_ptr<json::number_integer_t*>();
  11. auto p3 = value.get_ptr<json::number_integer_t* const>();
  12. auto p4 = value.get_ptr<const json::number_integer_t* const>();
  13. auto p5 = value.get_ptr<json::number_float_t*>();
  14. // print the pointees
  15. std::cout << *p1 << ' ' << *p2 << ' ' << *p3 << ' ' << *p4 << '\n';
  16. std::cout << std::boolalpha << (p5 == nullptr) << '\n';
  17. }