C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fixing Inheritance of Constructors from Aggregate bases

From: Bjorn Reese <breese_at_[hidden]>
Date: Tue, 9 Apr 2024 21:02:10 +0200
On 4/9/24 18:55, Barry Revzin wrote:

> David's proposal is about how we deal with inheriting constructors in
> the context of aggregate initialization. Your example didn't have an
> inherited constructor, so it would not have any effect.

Allow me to remedy my example:

   template <typename T> struct A { T a; };
   template <typename T> struct B : A<T> { using A<T>::A; T a; };
   B<int> b{ .a = 1, .a = 2 };

or to modify one of the examples from the proposal:

   struct W { Immovable a, b, c; };

   template <typename T>
   struct Inheritance : private T { using T::T; Immovable a; };

   Inheritance<W> a{ 1, 2, 3, 4 }; // Works today with public inheritance
   Inheritance<W> b{ .a = 1, .b = 2, .c = 3, .a = 4 }; // Ok?

Does the proposal enable the use of designated initializers somehow
for Inheritance<W>?

> As far as I can tell, what David's proposal A intends to be is that
> inherited constructors simply do not count for the purposes of
> determining aggregate status. That is:

Understood. The implementation of std::array could benefit from
this. I am merely trying to understand if there are unintended
consequences of the proposal.

Received on 2024-04-09 19:02:18