Boost logo

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_;
> };
> 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:


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?


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at