C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Idea: moved_from<T>() for Efficient Moved-From State Construction

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 24 Apr 2025 15:39:00 +0200
This proposal is still a solution looking for a problem. One huge
issue worth addressing is that C++ already incentivizes you to make
the default constructor and move constructor as simple as possible,
and shift the cost elsewhere.

Default constructors need to be kept simple because we do not have
non-transient constexpr allocations. Default constructors can often be
made constexpr and noexcept, unlike other constructors, and this
enables the developer to avoid dynamic initialization, which reduces
startup latency and sidesteps the dynamic initialization order fiasco.

Anyone who's making expensive default constructors is already making
questionable design decisions. Therefore, it makes no design sense for
a moved-from constructor to be any cheaper.

Received on 2025-04-24 13:39:15