C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Add array data initialization like in C

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Tue, 10 Nov 2026 17:13:53 -0500
On Tue, Nov 10, 2026 at 3:04 PM Comical USA via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> In C you can do
> int a[5] = {
> [3] = 2,
> };
> which will make the array 0, 0, 2, 0, 0
> but on C++ you can do that only with lambda or like this int a[] = { 0, 0,
> 2, 0, 0 } or after initializating you must do a[3] = 2; and it's pretty
> annoying, can we get in C++29 this C feature?
>

That's "designated initializers" — see cppreference
<https://en.cppreference.com/cpp/language/aggregate_initialization#Notes>.
C has them; C++20 got a relatively nerfed version of them.
P0329's rationale for omitting array-element initializers is found in
[diff.dcl] <https://eel.is/c++draft/diff.dcl#10.sentence-4>: "Array
designators conflict with *lambda-expression* syntax."
I'm not sure that they *quite* conflict, *really*; but I can contrive some
fun puzzles (Godbolt <https://godbolt.org/z/xbo63vGTP>) based on their
visual similarity and the untidiness of vendor extensions in this area.

https://quuxplusone.github.io/blog/2026/11/10/designated-or-lambda/

–Arthur

Received on 2026-11-10 22:14:12