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 11:39:52 -0700
On Thursday, 24 April 2025 11:27:06 Pacific Daylight Time Andrey Semashev via
Std-Proposals wrote:
> How would that change the practical state of things, compared to what
> Jon suggests? Ok, you have your valid() function that returns false for
> a moved-from object. You still are not allowed to call any methods on
> the ViewPort except destructor and assignment because now you have
> valid() as a precondition everywhere. So you're back to square one, only
> added a new valid() method that may be never needed by the user or the
> ViewPort implementer.
>
> I understand that the difference is in the formal contract with the
> user, which is more explicitly defined. But functionally preconditions
> "valid() returns true" and "not in moved-from state" are equivalent.
> Neither option is safer than the other as the compiler won't
> automatically test for valid(). That is unless ViewPort implementer adds
> asserts or otherwise checks for the moved-from state everywhere, which
> he could do with or without valid().

The difference would be that the default constructor would be allowed to create
such invalid state. That removes the need for std::moved_from<T>.

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

Received on 2025-04-24 18:39:57