Hasty Briefsbeta

Is C++26 getting destructive move semantics?

a day ago
  • #Memory Management
  • #Ownership
  • #C++
  • The text discusses the possibility of expressing a function that consumes an object, where the destructor is not run on the moved-from object.
  • It references the proposed library function `trivially_relocate_at` and questions whether users can achieve similar functionality.
  • The main problem identified is that the function signature does not clearly convey that it destructs an object at `src` or constructs an object at `dst`.
  • The author suspects that manual memory management with placement-new and `std::destroy_at` is currently the only way to achieve this.
  • The author proposes adding two new pointer qualifiers (`new` and `delete`) to express giving and taking ownership, aiming to enable static lifetime analysis similar to Rust in C/C++.
  • The goal is not optimization but enabling static ownership transfer for better lifetime analysis.