Boost logo

Boost :

From: Rainer Deyke (rdeyke_at_[hidden])
Date: 2020-10-07 05:20:58


On 06.10.20 21:50, Andrzej Krzemienski via Boost wrote:
> struct Person {
> std::string firstName;
> std::string lastName;
> int age;
> };
>
> struct Employee : Person {
> double salary;
> };
>
> struct Prisoner : Person {
> int cellNumber;
> };
> ```
> This (a) avoids duplication, and (b) I have the slicing do exactly what I
> need: convert an Employee to a Person. Now, I am disappointed with what
> C++17 did to aggregate initialization. My natural expectation would be that:
>
> ```
> Employee e {"Bilbo", "Baggins", 111, 1000.00};
> ```
> Flattens the class hierarchy and initializes each of the four members.
> Apparently , the C++ committee has a different vision for it. But I have
> noticed that if I changed derivation into aggregation (as I indicated
> earlier), the "flat" part of FPR would do exactly what I needed.

Does that example really work? My expectation would be that flat
reflection would try to break apart the std::strings, and fail with a
compile-time error because std::string is not an aggregate.

If it does work, then flat reflection is a lot more useful than I had
initially thought!

-- 
Rainer Deyke (rainerd_at_[hidden])

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