Hacker News new | ask | show | jobs
by lkiux 3594 days ago
They're not strictly the same, of course.

The trivial "safe" C++ linked list prevents you from dereferencing uninitialized memory, leaking resources and performing incorrect type conversions, which are the typical issues you'll find in any C linked-list implementation. But there's no compile-time check for the actual lifetime of the objects. This means you can manually destruct the same object twice, for example, and the compiler will not warn.

RAII can get you /very/ close, but since it's not enforced at the compiler level, Rust guarantee is definitely stronger.

My main point is that the strong guarantee comes also at a significant complexity cost, and I'm still not sold it's worth it in many conditions.