Conversation

I don’t know Rust, so I was wondering how this would look in C++, does anyone have an example?
Quote Tweet
Conceptually, the thing that makes Rust different from modern C++ (and other languages) is the "alias xor mutable" guideline, enforced by the borrow check. You could write C++ that way, but in practice nobody does. It's much stricter than just using smart pointers.
Show this thread
12
15
Mutex<T> and RwLock<T> naturally provide a dynamic implementation of those checks as part of implementing their interior mutability. Those give out objects representing locks with the destructor releasing the lock, similar to a modern C++ idiom, but safe.
1
2
RefCell<T> is similar within a single thread with dynamic failure on conflicts rather than waiting for the lock to be released. It's used in cases where statically checked borrow checking is too strict and can only support immutability due to shared ownership.
1
1
Show replies