get_ref.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 
00003 using json = nlohmann::json;
00004 
00005 int main()
00006 {
00007     // create a JSON number
00008     json value = 17;
00009 
00010     // explicitly getting references
00011     auto r1 = value.get_ref<const json::number_integer_t&>();
00012     auto r2 = value.get_ref<json::number_integer_t&>();
00013 
00014     // print the values
00015     std::cout << r1 << ' ' << r2 << '\n';
00016 
00017     // incompatible type throws exception
00018     try
00019     {
00020         auto r3 = value.get_ref<json::number_float_t&>();
00021     }
00022     catch (std::domain_error& ex)
00023     {
00024         std::cout << ex.what() << '\n';
00025     }
00026 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:02