Boost logo

Boost :

From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2021-03-08 09:38:09


wt., 2 mar 2021 o 18:02 Peter Dimov via Boost <boost_at_[hidden]>
napisał(a):

> Andrzej Krzemienski wrote:
> > wt., 2 mar 2021 o 16:34 Peter Dimov via Boost <boost_at_[hidden]>
> > napisał(a):
> >
> > > That's true, but Spirit relies on Fusion for the support of
> > > user-defined structs, so the straightforward way to make it work on
> > > described types is to make Fusion recognize them.
> > >
> >
> > Or have Spirit perform a check: if `describe::members` is found use it,
> > otherwise fall back to Boost.Fusion.
>
> That's possible, but it would require patching all uses of e.g.
> fusion::at_c
> in Spirit. It's easier to only add this support to fusion::at_c, which
> would
> not only take care of Spirit automatically, but of all other clients of
> Fusion.
>

Ok, I now have a better understanding of the matter. BoostFusion ADAPT
macros and Boost.Describe have different purpose and scope.

The goal of Boost.Describe is to emulate static reflection of declarations
in C++.

The goal of ADAPT macros in Boost.Fusion is to adapt a given class type as
a fusion sequence. This does not require respecting the data members of the
struct. For instance, I may have a struct `Point` that stores Cartessian
coordinate in 2D space, but when adapting as a fusion sequence, I may want
the data to be set as polar coordinates:

```
struct Point
{
    double x;
    double y;

    double get_distance() const;
    double get_angle() const;
    void set_distance(double r);
    void set_angle(double a);
};

BOOST_FUSION_ADAPT_ADT(
    Point,
    (obj.get_angle(), obj.set_angle(val))
    (obj.get_distance(), obj.set_distance(val)))
```

This is orthogonal to having reflection of structures.

I would still like Boost.Spirit to operate with Boost.Describe, but I do
not know how that maps on the idea for adapting Boost.Fuson to work with
Boost.Describe, and if the latter would be consistent with Boost.Fusion
design goals.

Regards,
&rzej;


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk