Allow default values in hana define struct
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 225
- PR merge metrics
- No merged PRs in 30d
Description
Current usage looks like this:
```
struct Person {
BOOST_HANA_DEFINE_STRUCT(Person,
(std::string, name),
(int, age)
);
};
```
It's not clear from this whether the members will be declared as `int age;` or `int age{};`. Either way, one can't easily control the behavior. You can write a default constructor for Person by hand, but this involves repeating all the members and still has some limitations where multiple constructors are involved compared to inline initializers. Inline initializers are a fantastic feature and it would be fantastic to be able to simply write:
```
struct Person {
BOOST_HANA_DEFINE_STRUCT(Person,
(std::string, name, "Bob"),
(int, age, 42)
);
};
```
Or something similar (you could for example, make the user write anything they want to be appear between the variable name and the semi colon, so it would instead be `(int, age, =42)`).
This would be very useful for my purposes; I use Hana with POD structs but sometimes it would be nice to control their default construction without lots of boilerplate.
Contributor guide
Research direction
Start by locating the implementation and documentation for BOOST_HANA_DEFINE_STRUCT, then review the issue's discussion before choosing a syntax. Done means the macro supports the requested member default-value behavior and the existing behavior remains covered by the project's tests.
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
- 25/100