Added struct flattening with tuple

This commit is contained in:
Patrick Urbanke
2023-11-15 21:45:09 +01:00
parent 5937bac8c3
commit f3cd5d04b4
2 changed files with 29 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
#include <cassert>
#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
void test_flatten_tuple() {
std::cout << "test_flatten_tuple" << std::endl;
using Person = std::tuple<std::string, rfl::Box<std::string>, int>;
struct Employee {
rfl::Flatten<Person> person;
rfl::Box<std::string> employer;
float salary;
};
const auto employee = Employee{
.person = Person{"Homer", rfl::make_box<std::string>("Simpson"), 45},
.employer = rfl::make_box<std::string>("Mr. Burns"),
.salary = 60000.0};
write_and_read(employee, R"(["Homer","Simpson",45,"Mr. Burns",60000.0])");
}
+2
View File
@@ -17,6 +17,7 @@
#include "test_field_variant.hpp"
#include "test_flatten.hpp"
#include "test_flatten_anonymous.hpp"
#include "test_flatten_tuple.hpp"
#include "test_forward_list.hpp"
#include "test_list.hpp"
#include "test_literal.hpp"
@@ -63,6 +64,7 @@ int main() {
test_timestamp();
test_flatten();
test_flatten_anonymous();
test_flatten_tuple();
test_deque();
test_forward_list();
test_list();