basic_json__CompatibleArrayType.cpp
Go to the documentation of this file.
00001 #include <json.hpp>
00002 #include <deque>
00003 #include <list>
00004 #include <forward_list>
00005 #include <set>
00006 #include <unordered_set>
00007 
00008 using json = nlohmann::json;
00009 
00010 int main()
00011 {
00012     // create an array from std::vector
00013     std::vector<int> c_vector {1, 2, 3, 4};
00014     json j_vec(c_vector);
00015 
00016     // create an array from std::deque
00017     std::deque<double> c_deque {1.2, 2.3, 3.4, 5.6};
00018     json j_deque(c_deque);
00019 
00020     // create an array from std::list
00021     std::list<bool> c_list {true, true, false, true};
00022     json j_list(c_list);
00023 
00024     // create an array from std::forward_list
00025     std::forward_list<int64_t> c_flist {12345678909876, 23456789098765, 34567890987654, 45678909876543};
00026     json j_flist(c_flist);
00027 
00028     // create an array from std::array
00029     std::array<unsigned long, 4> c_array {{1, 2, 3, 4}};
00030     json j_array(c_array);
00031 
00032     // create an array from std::set
00033     std::set<std::string> c_set {"one", "two", "three", "four", "one"};
00034     json j_set(c_set); // only one entry for "one" is used
00035 
00036     // create an array from std::unordered_set
00037     std::unordered_set<std::string> c_uset {"one", "two", "three", "four", "one"};
00038     json j_uset(c_uset); // only one entry for "one" is used
00039 
00040     // create an array from std::multiset
00041     std::multiset<std::string> c_mset {"one", "two", "one", "four"};
00042     json j_mset(c_mset); // only one entry for "one" is used
00043 
00044     // create an array from std::unordered_multiset
00045     std::unordered_multiset<std::string> c_umset {"one", "two", "one", "four"};
00046     json j_umset(c_umset); // both entries for "one" are used
00047 
00048     // serialize the JSON arrays
00049     std::cout << j_vec << '\n';
00050     std::cout << j_deque << '\n';
00051     std::cout << j_list << '\n';
00052     std::cout << j_flist << '\n';
00053     std::cout << j_array << '\n';
00054     std::cout << j_set << '\n';
00055     std::cout << j_uset << '\n';
00056     std::cout << j_mset << '\n';
00057     std::cout << j_umset << '\n';
00058 }


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