BOOST::HANA get all member names and iterate

399 views Asked by At

Coming from a Java/C# background and as a BOOST newbie, I have difficulty in getting a list of the class members.

I have the following struct/class.

class Configurations 
{
public:
    BOOST_HANA_DEFINE_STRUCT(Configurations,(float,c),(float,b));
};
Configurations configs; 

I came down to the point where I can iterate over the key/value pairs but I cannot figure out how to simply get a list of member variable names as strings as for to check if the member exists in the struct/class or not. I need to maintain a separate std::map that retains all the members names of the class/struct for a check later on to see if a certain member exits. I know I can use the for_each below and save the names, but is there a better way of doing this?

 boost::hana::for_each(configs, [](auto pair)
{
std::cout << boost::hana::to<char const*>(boost::hana::first(pair)) << ": "<< boost::hana::second(pair) << std::endl;
// Push the name into the std::map here
});    
    
0

There are 0 answers