-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-nan.cc
More file actions
54 lines (42 loc) · 1.22 KB
/
test-nan.cc
File metadata and controls
54 lines (42 loc) · 1.22 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
#include "json-struct.hh"
// ----------------------------------------------------------------------
class A
{
public:
inline A() : a(77), b(std::numeric_limits<decltype(b)>::quiet_NaN()) {}
double a;
double b;
friend inline auto json_fields(A& aa)
{
return std::make_tuple("a", &aa.a, "b", &aa.b);
}
};
// ----------------------------------------------------------------------
class B
{
public:
inline B() {}
std::vector<double> a;
std::string s;
friend inline auto json_fields(B& aa)
{
return std::make_tuple("a", &aa.a, "s", &aa.s);
}
};
// ----------------------------------------------------------------------
int main()
{
A a;
auto d = json::dump(a, 1);
std::cout << d << std::endl;
A a1;
json::parse(d, a1);
std::cout << json::dump(a1, 1) << std::endl;
std::string source_b = R"({"a": [null, 11, null], "s": "Null&NaN"})";
B b;
json::parse(source_b, b);
std::copy(b.a.begin(), b.a.end(), std::ostream_iterator<double>(std::cout, " ")); std::cout << std::endl;
std::cout << json::dump(b, 1) << std::endl;
return 0;
}
// ----------------------------------------------------------------------