2 ms·
Multiple mutable references can be problematic though: http://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/ http://manishearth.githu
by Manishearth 11y ago
Multiple mutable references can be problematic though: http://manishearth.github.io/blog/2015/05/17/the-problem-with-shared-mutability/ http://manishearth.github.io/blog/2015/05/17/the-problem-wit...
(Rust has Cell/RefCell if you need this, though)
- wuch 11y agoThanks for link. In C++ ensuring whether something is safe is indeed sometimes quite non-trivial, my favourite, but non-practical example is non-empty std::list<int> x, used in following way: x.remove(x.front()); Comment for non-C++ programmers: front method returns a reference to the first value in the list, and remove takes a const reference to value and removes all elements that compare equal to it. Problem is of course that after comparing first element with provided argument, it would compare equal and be subsequently deleted, making the reference invalid. As a side comment, I will note that above is in fact required to work, though it is probably not something you should write.
- Manishearth 11y agoI like this example a lot :)