Date: Wed, 16 Feb 2022 02:39:50 +1100
Gday all!
In generic contexts it can be desirable to inherit the constructors of a
base class. Currently, this leads to broken code when the base class is
an aggregate, as it is no longer possible to initialize the aggregate
base's members.
An example:
In generic contexts it can be desirable to inherit the constructors of a
base class. Currently, this leads to broken code when the base class is
an aggregate, as it is no longer possible to initialize the aggregate
base's members.
An example:
--- struct A { A(int a, int b, int c){} }; struct B { int a, b, c; }; template <typename T> struct N : T { using T::T; }; N<A> a{1, 2, 3}; // current: ok, inherits A::A N<B> b{1, 2, 3}; // current: error, no constructor to inherit(and `N<B>` is now, not an aggregate) // proposed: ok, elides the braces, and aggregate constructs N<B> c{.a = 1, .b = 2, .c = 3}; // current: error, designated initializers cannot be used with a non-aggregate type 'Bar' // proposed: ok, Foo's a, b, and c are initialized via the designated initalizers. --- Proposal is here: --- https://gitlab.com/Sepps/inheriting-aggregate-initialization
Received on 2022-02-15 15:39:56