mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Added struct flattening with tuple
This commit is contained in:
@@ -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])");
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user