-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-partial-array-output.cc
More file actions
66 lines (48 loc) · 1.33 KB
/
test-partial-array-output.cc
File metadata and controls
66 lines (48 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// #include <ctime>
#include "json-struct.hh"
// ----------------------------------------------------------------------
static void test1();
// ----------------------------------------------------------------------
class A
{
public:
inline A() : i(1) {}
inline A(int aI) : i(aI) {}
int i;
friend inline auto json_fields(A& a, bool for_output)
{
if (for_output && a.i % 2)
throw json::no_value();
return std::make_tuple("i", &a.i);
}
};
// ----------------------------------------------------------------------
class B
{
public:
std::vector<A> va;
friend inline auto json_fields(B& b)
{
return std::make_tuple("va", &b.va, "msg", json::comment("partial array output test"));
}
};
int main()
{
test1();
return 0;
}
// ----------------------------------------------------------------------
void test1()
{
int num_elements = 10;
// auto start = std::clock();
B b;
for (int i = 1; i <= num_elements; ++i)
b.va.emplace_back(i);
// std::cout << "making data " << (std::clock() - start) / double(CLOCKS_PER_SEC) << std::endl;
auto d = json::dump(b, 1);
std::cout << d << std::endl;
B b1;
json::parse(d, b1);
}
// ----------------------------------------------------------------------