MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / container_example1

Function container_example1

examples/src/container_examples.cpp:20–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18using namespace jsoncons;
19
20void container_example1()
21{
22 std::cout << "Convert from and to standard library containers\n" << '\n';
23
24 {
25 std::vector<int> v{1, 2, 3, 4};
26 json j(v);
27 std::cout << "(1) "<< j << '\n';
28 std::deque<int> d = j.as<std::deque<int>>();
29 }
30
31 std::vector<unsigned long> vec2{1ul, 2ul, 3ul, 4ul};
32 json j_vec2(vec2);
33 std::cout << j_vec2 << '\n';
34
35 std::deque<double> deque1{1.123, 2.234, 3.456, 4.567};
36 json j_deque1(deque1);
37 std::cout << j_deque1 << '\n';
38
39 std::list<bool> list1{true, true, false, true};
40 json j_list1(list1);
41 std::cout << j_list1 << '\n';
42
43 std::forward_list<int64_t>flist1 {12345678909876, 23456789098765, 34567890987654, 45678909876543};
44 json j_flist1(flist1);
45 std::cout << j_flist1 << '\n';
46
47 std::array<unsigned long, 4> array1 {{1, 2, 3, 4}};
48 json j_array1(array1);
49
50 std::set<std::string> set1{"one", "two", "three", "four"};
51 json j_set1(set1);
52 std::cout << j_set1 << '\n';
53 // ["four", "one", "three", "two"]
54
55 std::unordered_set<std::string> uset1{"one", "two", "three", "four"};
56 json j_uset1(uset1);
57 std::cout << j_uset1 << '\n';
58 // maybe ["two", "three", "four", "one"]
59
60 std::multiset<std::string> mset1{"one", "two", "one", "four"};
61 json j_mset1(mset1); // only one entry for "one" is used
62 std::cout << j_mset1 << '\n';
63 // maybe ["one", "two", "four"]
64
65 std::unordered_multiset<std::string> umset1 {"one", "two", "one", "four"};
66 json j_umset1(umset1); // both entries for "one" are used
67 // maybe ["one", "two", "one", "four"]
68
69 {
70 std::map<std::string,int> m{{"one",1},{"two",2},{"three",3}};
71 json j(m);
72 std::cout << "(1) " << j << '\n';
73 std::unordered_map<std::string,int> um = j.as<std::unordered_map<std::string,int>>();
74 }
75
76 std::unordered_map<std::string, double> umap1{ {"one", 1.2}, {"two", 2.3}, {"three", 3.4} };
77 json j_umap1(umap1);

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected