Files
reflect-cpp/tests/flexbuffers/test_optional_fields.cpp
T
2023-12-16 19:03:56 +08:00

37 lines
902 B
C++

#include "test_optional_fields.hpp"
#include <iostream>
#include <rfl.hpp>
#include <rfl/flexbuf.hpp>
#include <source_location>
#include <string>
#include <vector>
#include "write_and_read.hpp"
namespace test_optional_fields {
struct Person {
rfl::Field<"firstName", std::string> first_name;
rfl::Field<"lastName", std::string> last_name = "Simpson";
rfl::Field<"children", std::optional<std::vector<Person>>> children =
rfl::default_value;
};
void test() {
std::cout << std::source_location::current().function_name() << std::endl;
const auto bart = Person{.first_name = "Bart"};
const auto lisa = Person{.first_name = "Lisa"};
const auto maggie = Person{.first_name = "Maggie"};
const auto homer =
Person{.first_name = "Homer",
.children = std::vector<Person>({bart, lisa, maggie})};
write_and_read(homer);
}
} // namespace test_optional_fields