Boost logo

Boost :

From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2020-10-06 17:56:18


вт, 6 окт. 2020 г. в 14:42, Andrzej Krzemienski via Boost
<boost_at_[hidden]>:
>
> wt., 6 paź 2020 o 13:29 Peter Dimov via Boost <boost_at_[hidden]>
> napisał(a):
>
> > Andrzej Krzemienski wrote:
> >
> > > 3. The library buds on a basic concept of "Base-less aggregate".
> >
> > That's not really true though, is it? E.g.
> >
> > #include <boost/pfr.hpp>
> > #include <string>
> > #include <iostream>
> >
> > struct X
> > {
> > std::string a;
> > };
> >
> > struct Y
> > {
> > std::string b;
> > };
> >
> > struct Z: X, Y
> > {
> > std::string c;
> > };
> >
> > int main()
> > {
> > std::cout << boost::pfr::tuple_size_v<Z> << std::endl;
> > }
> >
> > compiles and prints "3". Bases are treated as members by the precise API.
> >
>
> But this is only for tuple_size. If you do a for_each, the compilation
> breaks:
>
> ```
> Z z {{}, {}, {}};
> boost::pfr::for_each_field(z, [](auto const&){});
> ```
>
> This is because brace initialization of aggregates is "incompatible" with
> structured binding for aggregates now in C++20.

I think we took the wrong turn in C++17, when allowed inheritance for
aggregates. Unfortunately that's not getting better with time :(

-- 
Best regards,
Antony Polukhin

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