C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 24 Apr 2025 08:56:31 -0700
On Thursday, 24 April 2025 08:04:27 Pacific Daylight Time Andrey Semashev via
Std-Proposals wrote:
> And it seems I'm not alone. I don't think we
> can say that the community is converging on the approach taken by the
> standard library.

As a library writer, I tend to follow the same design pattern as the Standard
Library for my public types. Having restricted operations on types leads to
headaches, either with users or with our future selves. I'd expect
restrictions to assignment and destruction to only be used for internal types,
not public library API ones.

Another point to consider are types that were designed *after* move semantics
came into existence. Because the general rule of thumb is to make your move
constructors noexcept, this would imply there is a state that can be created
noexceptly. And if such state can be created, it's usually the default-
constructed state because it's useful to make those noexcept too. If std::list
could break ABI today, it probably would choose a different solution that would
give it an efficient default constructed state.

>From my point of view, this proposal is trying to solve a non-problem. The
efficient moved-from state is already usually the default-constructed state, for
the overwhelming majority of types that can have such state and are liable to
be used in generic code.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel DCAI Platform & System Engineering

Received on 2025-04-24 15:56:33