mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 00:26:19 +08:00
Use names instead of types in the example
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user