mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-04 01:06:19 +08:00
Add a flatten anonymous test for flexbuffers
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/flexbuf.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
void test_flatten_anonymous() {
|
||||
std::cout << "test_flatten_anonymous" << std::endl;
|
||||
|
||||
struct Person {
|
||||
std::string first_name;
|
||||
rfl::Box<std::string> last_name;
|
||||
int age;
|
||||
};
|
||||
|
||||
struct Employee {
|
||||
rfl::Flatten<Person> person;
|
||||
rfl::Box<std::string> employer;
|
||||
float salary;
|
||||
};
|
||||
|
||||
const auto employee = Employee{
|
||||
.person = Person{.first_name = "Homer",
|
||||
.last_name = rfl::make_box<std::string>("Simpson"),
|
||||
.age = 45},
|
||||
.employer = rfl::make_box<std::string>("Mr. Burns"),
|
||||
.salary = 60000.0};
|
||||
|
||||
write_and_read(employee);
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "test_custom_constructor.hpp"
|
||||
#include "test_deque.hpp"
|
||||
#include "test_field_variant.hpp"
|
||||
#include "test_flatten_anonymous.hpp"
|
||||
#include "test_forward_list.hpp"
|
||||
#include "test_list.hpp"
|
||||
#include "test_literal.hpp"
|
||||
@@ -36,6 +37,7 @@ int main() {
|
||||
test_monster_example1();
|
||||
test_monster_example2();
|
||||
test_anonymous_fields();
|
||||
test_flatten_anonymous();
|
||||
test_optional_fields();
|
||||
test_unique_ptr();
|
||||
test_unique_ptr2();
|
||||
|
||||
Reference in New Issue
Block a user