3 ms·
That is a library design issue. You can certainly design a vector that is immutable by default and can only allow you to get references when immutable and pus
by fooker 9y ago
That is a library design issue.
You can certainly design a vector that is immutable by default and can only allow you to get references when immutable and push_back when mutable.
That is the point of C++, things other languages do at a language level you can easily design as a library without paying a cost if you do not use it.
- idsout 9y agoWhat does cost mean here? Performance? You do not pay a performance cost for borrowing semantics in rust.
- Eridrus 9y agoThis still doesn't solve the problem because there is nothing stopping you from having both immutable & non-immutable references to the same data structure. And does not enforce that there are no references hanging around when you go from immutable to mutable. Which is precisely what Rust does.