|
Boost : |
Subject: Re: [boost] [fusion] Getting the adapted structure's member names
From: Joel de Guzman (joel_at_[hidden])
Date: 2012-01-13 21:50:16
On 1/13/2012 9:35 PM, Andy Venikov wrote:
> struct alien {
> std::string color_;
> std::string planet_;
> bool benevolent_;
> };
>
> BOOST_FUSION_ADAPT_STRUCT(
> alien,
> (std::string, color_)
> (std::string, planet_)
> (bool, benevolent_)
> )
>
>
> I know how I can get to the actual member values, i.e. I could check
> at<2>(anAlien) to see if I should run away or not.
> But what if I wanted to get to the member names? (In this example it would
> be "color_", "planet_" and "benevolent_")
> It could be very useful for example for serialization that stores not just
> values but also the names of the values.
> Printing structures to stdout for inspection would be a breeze too.
> Since BOOST_FUSION_ADAPT_STRUCT is a macro, surely the member names could
> be strigized and stored somewhere.
The following is yet undocumented but has been stable for many years now:
boost::fusion::extension::struct_member_name<alien , N>::call()
where N is the index, will give you the name of the member. Ideally, we
need a fusion namespace level function for easy access to this. It's
reasonable to add something like:
boost::fusion::member_name_at_c<N>(anAlien);
for consistency with at_c, value_at_c, etc.
It would be easy to add those functions in the adapted module.
Would you like to volunteer creating a patch?
Regards,
-- Joel de Guzman http://www.boostpro.com http://boost-spirit.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk