|
Boost : |
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2020-10-06 11:42:05
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 still acknowledge that I may have not understood the requirement that PFR
puts on types. This makes my request even stronger: I have to know what it
expects of my types to work. I expect that this would work when I switch
between C++17 and C++20. (C++20 changed the initialization of aggregates:
base is treated as yet another member. But it did not change the structured
binding.)
Regards,
&rzej;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk