Can I express a function that consumes an object? Meaning that its destructor does not run on the moved object?
Like the proposed library function trivially_locate_at?
template
T* trivially_relocate_at(T* dst, T* src);
Intuitively, if library authors can do it, I should do it too.
Problem: Where’s the magic sauce? That function signature does not state that it effectively destroys an object. srcor the opposite problem, that it effectively creates an object dst,
I suspect the answer is no: the few examples I’ve found are avoiding this by doing manual memory management with placement-new and std::destroy_at.
Reason for asking: I would like to propose what seems to be missing: two new indicative qualifiers to express giving and taking ownership. If you can forgive my re-use new And delete Keywords for a moment (it doesn’t have to be the same):
template
T* trivially_relocate_at(new T* dst, delete T* src);
This is not about optimizing C++, but about saving it: to do static lifetime analysis (similar to Rust) in C and/or C++, I do not see any way to add the ability to express static ownership transfers.