Date: Thu, 24 Apr 2025 08:16:09 +0100
On Thu, 24 Apr 2025, 02:09 Elazar via Std-Proposals, <
std-proposals_at_[hidden]> wrote:
> Hey everyone,
>
> I've been working on a new proposal for the C++ Standard Library that I'd
> like to share: "A Library-Based Mechanism for Moved-From Initialization
> (moved_from())"
>
> *Problem:* Creating an object just to immediately overwrite it, like:
>
> BigExpensiveType obj; // Default construction we don't need
> obj = get_actual_value(); // Immediate overwrite
>
> This is especially wasteful for types with non-trivial constructors.
> Current workarounds like placement new or custom factory functions are
> either unsafe or non-standard.
>
Use std::optional, that's safe and standard.
std-proposals_at_[hidden]> wrote:
> Hey everyone,
>
> I've been working on a new proposal for the C++ Standard Library that I'd
> like to share: "A Library-Based Mechanism for Moved-From Initialization
> (moved_from())"
>
> *Problem:* Creating an object just to immediately overwrite it, like:
>
> BigExpensiveType obj; // Default construction we don't need
> obj = get_actual_value(); // Immediate overwrite
>
> This is especially wasteful for types with non-trivial constructors.
> Current workarounds like placement new or custom factory functions are
> either unsafe or non-standard.
>
Use std::optional, that's safe and standard.
Received on 2025-04-24 07:16:26