These are chat archives for boostorg/hana

15th
Aug 2018
jw0k
@jw0k
Aug 15 2018 15:10
Hi guys, I have a question about BOOST_HANA_ADAPT_STRUCT and inheritance. Is it possible to use this macro on a struct that inherits some base struct and then iterate over all elements of the derived struct (including inherited ones)?
Jason Rice
@ricejasonf
Aug 15 2018 16:33
Hey, unfortunately, the macro does not support that. There is an existing feature request though: boostorg/hana#339
jw0k
@jw0k
Aug 15 2018 16:48
@ricejasonf Thank you for the answer. Is someone working on it? If not, is it OK if I started working on it? Are pull requests welcome?
Jason Rice
@ricejasonf
Aug 15 2018 16:50
Yeah probably. I don't think he would have made an issue if it wasn't an acceptable idea.
Jason Rice
@ricejasonf
Aug 15 2018 17:06
@jw0k If you end up doing that, don't hesitate to submit the PR at an early stage so you can get feedback and what not.
jw0k
@jw0k
Aug 15 2018 17:25
OK, sure.
jw0k
@jw0k
Aug 15 2018 19:10

All right, I made a quick and dirty proof of concept that seems to work. You would use it like this:

struct Animal
{
    BOOST_HANA_DEFINE_STRUCT(Animal,
        (std::string, name)
    );
};

struct Dog : Animal
{
    BOOST_HANA_DEFINE_INHERITED_STRUCT(Dog, Animal,
        (double, tailLength)
    );
};

The problem is it only supports single inheritance. In case of multiple inheritance I'm not sure how to deal with 2 sets of variadic args in a macro at the moment

Jason Rice
@ricejasonf
Aug 15 2018 20:13
I think they had the same problem here: boostorg/hana#409
Maybe there could be a separate macro that merely defined the base classes of a class for introspection and the existing macro could check that
It would probably have to introduce a new concept like hana::StructInherited or something named better :P