BOOST_HANA_ADAPT_STRUCT with inheritance?
Asked Answered
I

0

6

Is there a way to use the BOOST_HANA_ADAPT_STRUCT macro for a struct that inherits from a base struct without repeating the accessors of the base struct ?

Right now I have something similar to the following example:

namespace hana = boost::hana;
namespace ns {
    struct Person {
       std::string name;
       int age;
    };
}
BOOST_HANA_ADAPT_STRUCT(ns::Person,
    name,
    age
);

namespace ns {
    struct Employer : Person {
       std::string company;
    };
}
BOOST_HANA_ADAPT_STRUCT(ns::Employer,
    name, // duplication
    age,  // duplication
    company
);
Inconvincible answered 9/4, 2017 at 6:22 Comment(2)
To make this possible, we would need to be able to get a list of base classes from a type or have a trait or macro that specify the base classes.Anhinga
There is no way to do that in Hana right now, but I filed this feature request for you.Teresaterese

© 2022 - 2024 — McMap. All rights reserved.