4 ms·
It's because const pointers aren't "deeply" immutable. For example, if we have a const Car*, we can reach into it to grab a (non-const) Engine* through which we
by verdagon 5y ago
It's because const pointers aren't "deeply" immutable. For example, if we have a const Car*, we can reach into it to grab a (non-const) Engine* through which we can modify things.
If there was a "imm" keyword in C++ which acted "deeply", that would get us pretty far towards our goal here. However, we'd then find ourselves in cases where we need to (for example) cast from an imm Engine* back to a (non-const) Engine*, often for values returned from functions. That's what this new "region borrow checker" concept would solve.
- WalterBright 5y agoIn D we call "deeply" immutable "transitive immutable". Interestingly, a transitive immutable data structure can be implicitly converted to transitive const, but not vice versa.
- fivea 5y ago> For example, if we have a const Car, we can reach into it to grab a (non-const) Engine through which we can modify things. Isn't that already deep within undefined behavior territory? That hardly is an adequate example, given that it spells an eggregious fault, the kind that's covered by any intro to C++ course with clear indications that it's nonsense.
- flqn 5y agoGetting a non-const reference out of a const object isn't undefined behaviour.