-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
66 lines (58 loc) · 1.32 KB
/
example.cpp
File metadata and controls
66 lines (58 loc) · 1.32 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 "type_streamer.h"
#include <iostream>
#include <utility>
#include <map>
#include <tuple>
enum class MyEnum { aaa, bbb };
enum class YourEnum { eee, fff };
struct Bar
{
unsigned x;
std::map<int, std::string> m;
MyEnum e1;
YourEnum e2;
};
struct Foo
{
int x;
std::vector<std::string> v;
std::pair<int, std::string> m;
Bar b;
std::tuple<int, std::string, const char*> t;
};
std::ostream& operator<<(std::ostream& out, MyEnum value)
{
switch(value)
{
case MyEnum::aaa:
return out << "aaa";
case MyEnum::bbb:
return out << "bbb";
}
return out;
}
std::ostream& operator<<(std::ostream& out, const Bar& value)
{
using namespace type_streamer;
return out << Struct{out, "Bar"}
.var("x", value.x)
.var("m", value.m)
.var("e1", value.e1)
.var("e1", value.e2)
;
}
std::ostream& operator<<(std::ostream& out, const Foo& value)
{
using namespace type_streamer;
return out << Struct{out, "Foo"}
.var("x", value.x)
.var("v", value.v)
.var("m", value.m)
.var("b", value.b)
.var("t", value.t)
;
}
int main()
{
std::cout << Foo{10, {"abc", "xyz"}, {7, "7"}, {1, {{1, "1"}, {2, "2"}}, MyEnum::bbb, YourEnum::fff}, {12, "tuple_elem1", "tuple_elem2"}} << "\n";
}