C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Deprecate and eventually remove std::initializer_list

From: Maciej Cencora <m.cencora_at_[hidden]>
Date: Fri, 27 Jun 2025 00:55:58 +0200
They already mean different things, the first one is aggregate
initialization with brace-ellision, the other one is a list-initialization
that invokes a user-defined constructor taking an std::initializer_list.
And that already doesn't mean the same thing - for aggregate if elements
are initialized from prvalue there is no-copy nor move, while for classes
the copy is unavoidable.

The problem is that these mean different things:
std::vector<int> a(1, 2);
std::vector<int> a{1, 2};

For me they should only differ in one thing - list initialization should
fail if it would trigger narrowing conversion (as it does now), but
otherwise it should select the same constructor as direct-initialization
(proposed behaviour).

Regards,
Maciej

pt., 27 cze 2025 o 00:38 Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> napisaƂ(a):

> So, you want:
>
> ```
> std::array<int, 5> arr{1, 2, 3, 4, 5};
> ```
>
> To mean one thing, while:
>
> ```
> std::vector<int> arr{1, 2, 3, 4, 5};
> ```
>
> To just... not work at all.
>
> Half the point of list initialization syntax is so that containers and
> aggregates can use the same syntax to achieve conceptually identical
> results.
>
> Now yes, if the array was of some move-only types, and the
> initializers were all prvalues, this wouldn't work with the `vector`
> version. But it would in basically every other case. What you're
> wanting makes it just never work at all.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-06-26 22:56:14