Use rfl::Variant

This commit is contained in:
Patrick Urbanke
2023-11-12 17:36:34 +01:00
parent a2c99ad37d
commit 7e7691500f
2 changed files with 18 additions and 18 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ void test_field_variant() {
rfl::Field<"width", double> width;
};
using Shapes = std::variant<rfl::Field<"circle", Circle>,
using Shapes = rfl::Variant<rfl::Field<"circle", Circle>,
rfl::Field<"rectangle", Rectangle>,
rfl::Field<"square", rfl::Box<Square>>>;
+17 -17
View File
@@ -8,27 +8,27 @@
#include "write_and_read.hpp"
void test_field_variant() {
std::cout << "test_field_variant" << std::endl;
std::cout << "test_field_variant" << std::endl;
struct Circle {
rfl::Field<"radius", double> radius;
};
struct Circle {
rfl::Field<"radius", double> radius;
};
struct Rectangle {
rfl::Field<"height", double> height;
rfl::Field<"width", double> width;
};
struct Rectangle {
rfl::Field<"height", double> height;
rfl::Field<"width", double> width;
};
struct Square {
rfl::Field<"width", double> width;
};
struct Square {
rfl::Field<"width", double> width;
};
using Shapes = std::variant<rfl::Field<"circle", Circle>,
rfl::Field<"rectangle", Rectangle>,
rfl::Field<"square", rfl::Box<Square>>>;
using Shapes = rfl::Variant<rfl::Field<"circle", Circle>,
rfl::Field<"rectangle", Rectangle>,
rfl::Field<"square", rfl::Box<Square>>>;
const Shapes r =
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});
const Shapes r =
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});
write_and_read(r, R"({"rectangle":{"height":10.0,"width":5.0}})");
write_and_read(r, R"({"rectangle":{"height":10.0,"width":5.0}})");
}