Boost logo

Boost :

Subject: Re: [boost] DRYing BOOST_FUSION_ADAPT_STRUCT with decltype/Boost.TypeOf ?
From: Joel de Guzman (djowel_at_[hidden])
Date: 2013-12-19 17:46:24

On 12/18/13, 9:35 AM, Damien Buhl wrote:
> Hi dear Boost Fusion developers,
> I was asking myself if there were already plan to improve BOOST_FUSION_ADAPT_STRUCT to benefit from C++11 features like decltype ? This would be interesting to avoid the risk encountered that the types definitions can get out-of-sync. And would avoid typing type declarations twice.
> Currently there is BOOST_FUSION_DEFINE_STRUCT to avoid repeating the type information for each field. However this is something that makes most developer I know unhappy, as it obliges to modify the readable C++ aggregate types definition (i.e. Could be public headers) with this macro.
> Then there is the nice choice of BOOST_FUSION_ADAPT_STRUCT which obliges retyping the type and adds the risk that some field type information could get out-of-sync between the struct definition and the BOOST_FUSION_ADAPT_STRUCT listing.
> I think it would be valuable to add macros that would enable to select the fields that we want to adapt to a Random Access Sequence without requiring to repeat the type information. I would find more comfortable to write the example provided here as follow :
> namespace demo
> {
> struct employee
> {
> std::string name;
> int age;
> };
> }
> // demo::employee is now a Fusion sequence
> demo::employee,
> (name)
> (age))
> And a naïve implementation of BOOST_FUSION_ADAPT_STRUCT_EXT could be:
> #include <boost/typeof/typeof.hpp>
> #include <boost/fusion/include/adapt_struct.hpp>
> #include <boost/preprocessor/seq/for_each.hpp>
> #define ATTRIBUTE_DEFINITION(r, data, elem) \
> (BOOST_TYPEOF(data::elem), elem) \
> #endif
> The same could certainly be achieved for BOOST_FUSION_ADAPT_TPL_STRUCT, while I didn't check.
> Thanks for the really great job done in Boost.Fusion.

Thanks, Damien. I like the idea. Could you 1) try it out and
2) submit a patch (or pull request). It would also be super if
you can add in the doc patch.


Joel de Guzman

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