|
|
Invisible wrote:
> I wrote a function that returns the top element from the stack while
> simultaneously removing it. That cuts down the typing quite a bit.
The reason that isn't built-in is that it doesn't work well with objects.
If vector.pop_back() returned a reference to the popped object, you'd get
sure crashes (reading from freed memory, or at least, a destructed object).
If vector.pop_back() returned a copy of the popped object, you'd get bad
performance even when you don't need the object (useless copying), you just
want to remove it. And who would free that copy?
ints, however, are easily copyable and don't need "freeing" :)
Post a reply to this message
|
|