C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Inheriting Aggregate Initialization with using T::T

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Tue, 15 Feb 2022 17:49:26 +0200
On Tue, 15 Feb 2022 at 17:40, David Ledger via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> 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:
>
> ---
> 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

So, the problem is that a using-declaration that inherits constructors
renders a type a non-aggregate even if it inherits
an aggregate?

At the first glance, "Ignore using T::T for aggregates completely."
seems like a good idea to me. And in general, I agree that this would
be a good fix to make, not 100% of which approach is the best. The
"ignore" option seems like it does all the right things, afaics.

Received on 2022-02-15 15:49:38