Skip to content

Auto-generated ext_h101 structs #865

@klenze

Description

@klenze

When I stated, in my musings in #712

actually you can not, because the spoilsports at ISO do not allow to either define a nameless class nor use a class definition instead of a class name in either a template parameter (pack) or an inheritance specification.

I was wrong. (I am unsure if my C++ is good enough to make this a case of me fulfilling Clarke's first law.)

While you can not directly pass on anonymous classes as template parameters, you can certainly pass lambda expressions returning arbitrary types as template parameters, which is sufficient.

See proof of concept here. (Trigger warnings: C++, preprocessor macros, virtual inheritance, variadic templates).

The gist is that you can run

  All<MKCLASS(Foo), MKCLASS(Bar), MKCLASS(Baz)> a;
  a.onInit();

where a will have members fFoo, fBar and fBaz and onInit will call lambdas which have access to their variables and the names of these variables as a string.

For zero suppressed 1d arrays, we could have a macro which takes a name Foo and defines Foo, FooI and Foov appropriately, as well as calling the correct EXT_STR_ITEM_INFO_... for them.

Arguments could be easily added to the onInit and the lambda expressions. The handling of n-dimensional arrays is left as an exercise for the reader. So is passing stuff to constructors, if one needed that for some reason.

I think in the spirit of "Don't Repeat Yourself" (DRY), it is better to have this in one place instead of having longish macros saying map the variable Foo to "Foo" for 100s of variables.

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