Skip to content

feat(utility): add reconstruct_at - #12

Closed
codethinki wants to merge 1 commit into
masterfrom
feat/reconstruct-at
Closed

codethinki wants to merge 1 commit into
masterfrom
feat/reconstruct-at

Conversation

@codethinki

Copy link
Copy Markdown
Owner

cth::reconstruct_at(object, std::move(other)) destroys object and move constructs it from other in place. It is a move assignment for types where = default is wrong, e.g. types that own a resource through cth::move_ptr, whose move assignment overwrites without destroying:

Device& operator=(Device&& other) noexcept { return cth::reconstruct_at(*this, std::move(other)); }
  • noexcept: requires a nothrow move constructor and destructor, a throw after the destruction would leave a dead object
  • rejects polymorphic types, std::destroy_at would run the most derived destructor
  • self assignment is a no op
  • preconditions (not checkable): object is not a base class subobject or [[no_unique_address]] member, and does not own other

cth_engine uses it for its Vulkan handle classes.

Destroys the object at a location and move constructs it from other in place, like std::destroy_at and std::construct_at. For move assignment operators of types where = default leaks a resource.
@codethinki

Copy link
Copy Markdown
Owner Author

Not merging: move assignment through destroy + reconstruct in place is UB on base class subobjects, too easy to misuse. cth_engine uses std::unique_ptr with a deleter that holds the destroy context instead.

@codethinki codethinki closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant