3 ms·
Edited to inject: Actually on second thoughts maybe none of these even do what you thought they did, they're even sillier than I'd assumed. So funny thing, you
by tialaramex 1y ago
Edited to inject: Actually on second thoughts maybe none of these even do what you thought they did, they're even sillier than I'd assumed.
So funny thing, your C++ 26 solution doesn't do what my Rust function does.
Actually even the first one doesn't, but you likely don't really care about a std::unique_ptr, so it doesn't feel like a difference, and the negligence only really bites when it's not "just" that pointer type.
You see that Rust function destroyed the T. It's gone, no more T. But your C++ function makes a new T, then destroys the old one, so there's still a T, it's not gone after all.
- fooker 1y ago> You see that Rust function destroyed the T. It's gone, no more T. But your C++ function makes a new T, then destroys the old one, so there's still a T, it's not gone after all. Perhaps your idea of C++ semantics is a bit off?
- tialaramex 1y agoAfter more consideration I think probably your functions don't do anything at all? Is that the joke here? That despite everything you didn't understand why core::mem::drop has that definition and so reading the empty body you assumed that you can just not do anything and that'll work in C++ ?
- fooker 1y agoAre you trolling? Or do you genuinely not understand why it might work in C++? https://godbolt.org/z/58TqTTM37 https://godbolt.org/z/58TqTTM37
- tialaramex 1y agoNo, I'm not trolling, I'll give you the benefit of the doubt, try this C++: https://godbolt.org/z/zM3oxjrfn https://godbolt.org/z/zM3oxjrfn and contrast this Rust: https://rust.godbolt.org/z/1rMYcqY65 https://rust.godbolt.org/z/1rMYcqY65 In your unique_ptr<T> example what you'd hidden (from me? Or perhaps from yourself) was that we're not destroying the unique_ptr, we're just destroying the Foo, and since the unique_ptr is null the destructor for that will be silent when the scope ends.