forked from fabian-jung/tsmp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_encode.cpp
39 lines (34 loc) · 827 Bytes
/
json_encode.cpp
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
#include "tsmp/json.hpp"
#include <fmt/format.h>
enum class state_t
{
A,
B,
C
};
struct foo_t
{
state_t state = state_t::A;
int i{42};
// immutable_t<4> version;
tsmp::string_literal_t<4> sl{"asdf"};
// tsmp::immutable_t<tsmp::string_literal_t{"some_string"}> immutable_string;
float f{1337.0f};
std::string s = "Hello World!";
struct bar_t
{
int i{0};
} bar;
std::array<int, 4> numbers_array{1, 2, 3, 4};
std::vector<int> numbers_vector{1, 2, 3, 4};
std::optional<int> oint = std::nullopt;
std::variant<std::string, int> variant{5};
};
int main(int, char*[])
{
foo_t foo;
fmt::print("{}\n", tsmp::to_json(foo));
foo_t foo2 = tsmp::from_json<foo_t>(tsmp::to_json(foo_t{}));
fmt::print("{}\n", tsmp::to_json(foo2));
return 0;
}