-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscratchpad.cpp
More file actions
73 lines (58 loc) · 1.82 KB
/
Copy pathscratchpad.cpp
File metadata and controls
73 lines (58 loc) · 1.82 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
67
68
69
70
71
72
73
#include <cmcpp.hpp>
#include "host-util.hpp"
using namespace cmcpp;
#include <doctest/doctest.h>
#include <iostream>
#include <vector>
#include <utility>
#include <cassert>
// Traits ---
#include "boost/pfr.hpp"
// Helper function to create a struct from a tuple
template <typename T, typename Tuple, std::size_t... I>
T construct_from_tuple_impl(const Tuple &t, std::index_sequence<I...>)
{
return T{std::get<I>(t)...};
}
template <typename T, typename Tuple>
T construct_from_tuple(const Tuple &t)
{
constexpr auto size = std::tuple_size<Tuple>::value;
return construct_from_tuple_impl<T>(t, std::make_index_sequence<size>{});
}
struct Person
{
string_t name;
uint16_t age;
uint32_t weight;
};
struct PersonEx : Person
{
string_t address;
};
TEST_CASE("Records")
{
Heap heap(1024 * 1024);
auto cx = createLiftLowerContext(&heap, Encoding::Utf8);
PersonEx p = {"John", 42, 200, "123 Main St."};
auto x = boost::pfr::structure_to_tuple<Person>(p);
Person y = construct_from_tuple<Person>(x);
// auto t = struct_to_tuple(p);
// auto xxx = ValTrait<Person>::get<1>(p);
// CHECK(ValTrait<Person>::type == ValType::Record);
// auto v = lower_flat_test(*cx, p);
// auto rr = lift_flat<Person>(*cx, v);
// CHECK(r0 == rr);
// MyRecord0 r0 = {42, 43};
// // auto str0 = to_struct<MyRecord0>(rr);
// MyRecord1 r1 = {142, 143, "Hello"};
// auto vv = lower_flat(*cx, r1);
// auto rr1 = lift_flat<MyRecord1>(*cx, vv);
// CHECK(r1 == rr1);
// // auto str1 = to_struct<MyRecord1>(rr1);
// MyRecord2 r2 = {242, 243, "2Hello", {"2World", "!"}};
// auto vvv = lower_flat(*cx, r2);
// auto rr2 = lift_flat<MyRecord2>(*cx, vvv);
// CHECK(r2 == rr2);
// // auto str2 = to_struct<MyRecord2>(rr2);
}