Use names instead of types in the example

This commit is contained in:
liuzicheng1987
2023-10-04 20:11:29 +02:00
committed by GitHub
parent 4017487b8a
commit 4fc826321d
+4 -4
View File
@@ -136,12 +136,12 @@ const Shapes my_shape =
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});
const auto handle_shapes = [](const auto& field) {
using Type = typename std::decay_t(decltype(field))::Type;
if constexpr (std::is_same<Type, Circle>()) {
using Name = typename std::decay_t(decltype(field))::Name;
if constexpr (std::is_same<Name, rfl::Literal<"circle">>()) {
std::cout << is circle, radius: << field.value().radius() << std::endl;
} else if constexpr (std::is_same<Type, Rectangle>()) {
} else if constexpr (std::is_same<Name, rfl::Literal<"rectangle">>()) {
std::cout << is rectangle, width: << field.value().width() << ", height: " << field.value().height() << std::endl;
} else if constexpr (std::is_same<Type, Square>()) {
} else if constexpr (std::is_same<Name, rfl::Literal<"rectangle">>()) {
std::cout << is square, width: << field.value().width() << std::endl;
} else {
// reflect-cpp also provides this very useful helper that ensures