C++ Logo

std-proposals

Advanced search

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

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Thu, 24 Apr 2025 10:32:03 +0300
On 24 Apr 2025 04:14, Jason McKesson via Std-Proposals wrote:
>
> Many `std::list` implementations need to have an allocated node to
> function. So the default constructor creates one. But the move
> constructor *also* allocates one for the moved-from object, since
> moved-from objects have to still be valid (this is also why
> `std::list`'s move constructor is not required to be noexcept). So
> it's unclear when exactly this would be advantageous.

A moved-from object only needs to be destructible and assignable-to. It
doesn't need to be valid for any other operations. In your std::list
example, the move assignment/constructor can leave the moved-from object
without the node, if the std::list's destructor and assignment support
that state.

Received on 2025-04-24 07:32:06