C++ Logo

std-discussion

Advanced search

Re: Array initialization

From: <rjshaw_at_[hidden]>
Date: Tue, 07 Apr 2026 06:56:55 +0000
On Tue Apr 07 2026 Andrey Tarasevich <atarasevich_at_[hidden]> wrote:

>
> ---------- Original Message ----------
>
> It refers to the `()`-enclosed version of aggregate-like initialization,
> which became available in C++20. E.g.
>
> int a[]( 1, 2, 3, 4 );
> struct
> XY { int x, y; } xy( 1, 2 );
>
> > On 04/06/2026 7:17 PM PDT rjshaw--- via
> Std-Discussion < std-discussion_at_[hidden] > wrote:
> >
> >
> > In
> [dcl.init.general] :
> >
> >
> -------------------------------------------------------------------------------------------------------
> > — If the initializer is a (non-parenthesized) braced-init-list or is =
> braced-init-list, the object or reference is
> > list-initialized (9.4.5).
> >
> > ...
> >
> > — Otherwise, if the destination type is an array, the object is
> initialized as follows. Let x1 , . . . , xk be
> > the elements of the
> expression-list. ...
> >
> -------------------------------------------------------------------------------------------------------
> >
> > The first case is for constructs like "int a[] = {1,2,3};", because
> "a" is an "object" [dcl.array].
> >
> > What construct does the second case
> apply to ?

Hi,

I forgot about that way of inititialization and missed the obvious:

initializer :

brace-or-equal-initializer

( expression-list )

Received on 2026-04-07 06:57:05