5 ms·
Thanks 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
by wuch 11y ago
Thanks 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 :)