C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Improving std::initializer_list for Move Semantics

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sun, 24 Nov 2024 17:04:34 -0500
On Sun, Nov 24, 2024 at 4:49 PM James via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Currently `std::initializer_list` stores elements as `const T*`, which
> prevents moving them. While this works well for simple types, it can be
> inefficient for types that manage resources.
>
> Are there any plans or ongoing discussions about enhancing
> `std::initializer_list` to support move semantics?
>
> Also it clashes with uniform initialization, but I don't know if something
> can be done about it
>
The short answer is "nope, no plans, nothing can be done."
I highly recommend this talk by Jason Turner at C++Now 2018: "Initializer
Lists are Broken; Let's Fix Them."
<https://www.youtube.com/watch?v=sSlmmZMFsXQ>
But even in 2018, it was about seven years too late to change anything in
either of those departments.

Previous attempts in that department include:
- N2801 "mutable_initializer_list<T>"
<https://www9.open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2801.pdf>
(Rodrigo Castro Campos, 2008)
- P0065 "Movable initializer lists"
<https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0065r0.pdf>
(David Krauss, 2015)

HTH,
Arthur

Received on 2024-11-24 22:04:48