Files
reflect-cpp/tests/test_variant.hpp
T
2023-10-02 21:53:28 +02:00

33 lines
708 B
C++

#include <cassert>
#include <iostream>
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <string>
#include <vector>
#include "write_and_read.hpp"
// Makes sure that we can set default values.
void test_variant() {
std::cout << "test_variant" << std::endl;
struct Circle {
rfl::Field<"radius", double> radius;
};
struct Rectangle {
rfl::Field<"height", double> height;
rfl::Field<"width", double> width;
};
struct Square {
rfl::Field<"width", double> width;
};
using Shapes = std::variant<Circle, Rectangle, Square>;
const Shapes r = Rectangle{.height = 10, .width = 5};
write_and_read(r, "{\"height\":10.0,\"width\":5.0}");
}