Open johnjohnlin opened 1 year ago
Hi, and thanks for your interest!
I think the best way forward here would be to integrate with Boost.Describe as discussed in #498. WDYT?
Agree, seems that Boost.Describe provides sufficient functionalities for type reflection. I shall avoid inventing the wheel.
Maybe I can try whether using Boost.Describe can also provide good compile time performance.
Hi developers, I have used
BOOST_HANA_DEFINE_STRUCT
in my project and find it very useful. Thanks for the great work. When I was using the library, I came up with an idea that makes a similarBOOST_HANA_DEFINE_STRUCT
, with much shorter compile time. I made a proof-of-concept and it shows 5x time saving and 4x memory saving (will show later).Since Hana is a library that features fast compile time, I think my proposal can help makes Hana a better library, and I want to make contribution.
The proposal is a macro like
BOOST_HANA_ADAPT_STRUCT
.Using this macro,
MyStruct
almost becomes a tuple, bound with member name.my.get<0>()
isa
my.get<1>()
isb
my.get<2>()
isc
my.get<3>()
isd
MyStruct::get_name(0)
is"a"
MyStruct::get_name(1)
is"b"
MyStruct::get_name(2)
is"c"
MyStruct::get_name(3)
is"d"
MyStruct::num_members
is4
This acts like python
namedtuple
, which allows iterating all members/names using fold expression (c++17) or recursion (pre c++17).For example, this
namedtuple
allowed me to create a generic argument parser works as below:Or I can implement a generic JSON print function like the example in
Hana::Struct
.The implemention of
namedtuple
is simple. Withboost.preprocessor
I only need 10 lines of macro, which is expanded to:The benchmark is accessible here. How do you think about this proposal? If you consider this is suitable, can you instruct me some ways to glue this
namedtuple
into Hana?