I am trying to use boost fusion for one of my projects and I an figuring out how to get type names and variable names for structures and classes.
#include &
I distilled the answer by sehe into something much simpler, provided you are using C++14
#include
#include
#include
#include
#include
struct MyStruct {
std::string foo;
double bar;
};
BOOST_FUSION_ADAPT_STRUCT(MyStruct,
foo,
bar)
namespace fuz = boost::fusion;
namespace mpl = boost::mpl;
int main(int argc, char* argv[]) {
MyStruct dummy{"yo",3.14};
fuz::for_each(mpl::range_c<
unsigned, 0, fuz::result_of::size::value>(),
[&](auto index){
std::cout << "Name: "
<< fuz::extension::struct_member_name::call()
<< " Value: "
<< fuz::at_c(dummy) << std::endl;
});
}
Outputs:
Name: foo Value: yo
Name: bar Value: 3.14
See it live on coliru