Adapted the documentation to the possibility of leaving out rfl::Field

This commit is contained in:
Patrick Urbanke
2023-11-28 19:09:41 +01:00
parent 456fc33613
commit 8ff4d105c6
15 changed files with 277 additions and 212 deletions
+32 -1
View File
@@ -9,7 +9,38 @@ all fields will be flattened to a single JSON object.
If there are duplicate field names, you will get a compile-time error.
## Example: Every employee is a person.
## Example: Every employee is a person
```cpp
struct Person {
std::string first_name;
std::string last_name;
int age;
};
struct Employee {
rfl::Flatten<Person> person;
std::string employer;
float salary;
};
const auto employee = Employee{
.person = Person{.first_name = "Homer",
.last_name = "Simpson",
.age = 45},
.employer = "Mr. Burns",
.salary = 60000.0};
const auto json_str = rfl::json::write(employee);
```
This flattens all fields into a single JSON object:
```json
{"first_name":"Homer","last_name":"Simpson","age":45,"salary":60000.0}
```
## Example, using the `rfl::Field`-syntax.
```cpp
struct Person {