3 ms·
> C++ has a perfect match for Rust’s mutability: const and non-const. Rust has inherited mutability, while I believe const in C++ is shallow. I don't think it'
by wtetzner 9mo ago
> C++ has a perfect match for Rust’s mutability: const and non-const.
Rust has inherited mutability, while I believe const in C++ is shallow. I don't think it's a perfect match.
- mgaunard 9mo agomembers of a const struct are also const. Now you obviously can still have escape hatches and cast the const away whenever you want.
- wtetzner 9mo ago> members of a const struct are also const. Yes, but if your struct contains references, the constness doesn't apply to what those references point to. In Rust it does.
- mgaunard 9mo agoFor pointers, const only affects whether you can re-set it to point to something else, not the pointee. Nothing prevents you from building a smart pointer with those semantics though, std::indirect is an example of this (arguably closer to Rust's Box).