boostorg / boostorg/hana

Include base class members in BOOST_HANA_ADAPT_STRUCT

Open
#339 4 comments 8 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
1.9k
Forks
225
PR merge metrics
No merged PRs in 30d

Description

Feature request lifted from [this](http://stackoverflow.com/q/43303700/627587) StackOverflow question:

> 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:
>
> ```c++
> 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
> );
> ```

Like @ricejasonf says in the comments, I don't think it's possible to do this out of the box (without reflection). However, it would be possible to do it if the macro received the set of base classes or something like that. We would then check that each base class is indeed a base class, and we would concatenate the members of both (or something like that).

Contributor guide

Open the contributing guide

Research direction

Start at the BOOST_HANA_ADAPT_STRUCT macro and inspect how it currently collects member accessors. Determine how a supplied base class could be validated and combined with the derived struct's members. Done means an adapted derived struct can include inherited members without repeating their accessors.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.