2 ms·
I think you are discussing different things, and in the process missing the whole point. It's one thing for an object to be immutable throughout is life cycle.
by fivea 5y ago
I think you are discussing different things, and in the process missing the whole point.
It's one thing for an object to be immutable throughout is life cycle. That's immaterial to this discussion.
It's an entirely different thing that the same object cannot be changed within specific contexts.
If you want to ensure that a thread has read access to an object and it cannot be changed accidentally then passing a const reference to that object already ensures that. That's pretty much the whole point of const.
- flqn 5y agoI think you are missing that const is insufficient for safe concurrency; it requires programmer discipline to ensure there are no shared mutable references. Const also has no bearing on lifetimes. Constexpr/consteval do, but those objects always have static lifetime so it's sort of irrelevant.