Skip to content

Externally tagged unions as fields #481

@GregTheMadMonk

Description

@GregTheMadMonk

Hello!

After reading https://github.com/getml/reflect-cpp/blob/main/docs/variants_and_tagged_unions.md I was under the impression that I would be able to do something like:

struct Rectangle { /*...*/ };
struct Circle    { /*...*/ };

struct Shape {
    std::string custom_name;
    rfl::Variant<rfl::Field<"rectangle", Rectangle>, rfl::Field<"circle", Circle>> shape;
}; // <-- struct Shape

but it still requires for the "shape" member to be present in JSON and only under that does generate the correct children. I tried to rfl::Flatten it, but it gave a compile-time error.

I understand, this is not really supported at that moment? How hard will it be to add it? Where should I start if I wanted to add support for such syntax?

P.S. Ofc this could be done by making Shape a template and (de)serializing a variant on that, but I really wanted to avoid it. Unless, of course, reflect-cpp is strictly tied to the idea of struct having a fixed set independent fields and there is no way to fit syntax like that into the design of the library.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions