In the good old days we used to adapt a struct into a Boost.Fusion container or an associative container with
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/adapted/struct/adapt_assoc_struct.hpp>
struct Person{
std::string name;
int age;
};
BOOST_FUSION_ADAPT_STRUCT(
Person,
(std::string, name)
(int, age)
);
struct tag_name;
struct tag_age;
BOOST_FUSION_ADAPT_ASSOC_STRUCT(
Person,
(std::string, name, tag_name)
(int, age, tag_age));
int main(){}
Now with Boost.Hana we can also adapt
#include <boost/hana/adapt_struct.hpp>
BOOST_HANA_ADAPT_STRUCT(Person,
name,
age
);
The question: Is there a sort of BOOST_HANA_ADAPT_ASSOC_STRUCT (equivalent to BOOST_FUSION_ADAPT_ASSOC_STRUCT) in Boost.Hana? Or is this done differently now?
Bonus question: Is there a BOOST_HANA_ADAPT_TPL?
According to the documentation of Boost.Fusion the
BOOST_FUSION_ADAPT_ASSOC_STRUCTmacro generates boiler plate for modeling Random Access Sequence and Associative Sequence.With Boost.Hana these additional macros are not needed as you get additional functionality for free without any boiler plate.
For "Associative Sequence", Boost.Hana has the
Searchableconcept that provides theat_keyfunction.While Boost.Hana does not have iterators for "Random Access Sequence", it does have the functions
atandat_cin Boost.Hana'sIterableconcept. Unfortunately Boost.Hana'sStructdoes not implement these although I believe it could. Perhaps that could be added.As for
BOOST_HANA_ADAPT_TPL, Boost.Hana has no macro for facilitating template structs, but users can still implementhana::accessorsto make aStructwithout any macro.You can search
boost::hana::Structs members by their name with a compile-time string: