Skip to content

Commit

Permalink
Added flag enums in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Dec 20, 2023
1 parent c5347ee commit 5f07340
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,22 +165,29 @@ Found 5 errors:
reflect-cpp supports scoped enumerations:

```cpp
enum class Color { red, green, blue, yellow };
enum class Shape { circle, square, rectangle };

struct Circle {
float radius;
enum class Color { red = 256, green = 512, blue = 1024, yellow = 2048 };

struct Item {
float pos_x;
float pos_y;
Shape shape;
Color color;
};

const auto circle = Circle{.radius = 2.0, .color = Color::green};
const auto item = Item{.pos_x = 2.0,
.pos_y = 3.0,
.shape = Shape::square,
.color = Color::red | Color::blue};

rfl::json::write(circle);
rfl::json::write(item);
```
This results in the following JSON string:
```json
{"radius":2.0,"color":"green"}
{"pos_x":2.0,"pos_y":3.0,"shape":"square","color":"red|blue"}
```

## Algebraic data types
Expand Down

0 comments on commit 5f07340

Please sign in to comment.