News for hackers. Stuff that matters.
Re:You can't make C++ not ugly, but you can't not try (2010) by mehrdadn on Thursday February 27, 2020 @06:22AM (#22432342)
Small vectors break iterator guarantees, for one thing. They also really only make sense for tiny objects (ints, etc.) given you don't want a pickup truck's worth of data on your stack. They're most definitely not general-purpose.

There are lots of subtleties STL containers have to worry about in designing containers, regarding everything from iterator & pointer invalidation to allocation and allocator propagation. All this is because they're designed to be general-purpose and support most conceivable use cases. Their replacements have to trade off requirements in order to get better performance or otherwise improve on some axes.

Re:You can't make C++ not ugly, but you can't not try (2010) by kllrnohj on Thursday February 27, 2020 @12:23PM (#22435390)
> Small vectors break iterator guarantees, for one thing.

It only breaks swap of the container itself during iteration. Which is a super niche condition.

And that swap also invalidates some of std::vector's iterators as well - specifically the end() iterator.

> They also really only make sense for tiny objects (ints, etc.) given you don't want a pickup truck's worth of data on your stack. They're most definitely not general-purpose.

Of course they are still general-purpose. They can (and do) specialize on the size of the object being contained. The only reason std::vector doesn't also have SSO is because it's an ABI break. Not because it's better in some way or less fragile. Legacy is the only reason.

Re:You can't make C++ not ugly, but you can't not try (2010) by mehrdadn on Thursday February 27, 2020 @01:06PM (#22435876)
> And that swap also invalidates some of std::vector's iterators as well - specifically the end() iterator.

And they don't invalidate the iterators that point to actual elements, which was kind of the entire point I was making. Don't let that stop you from trying to make it look like I'm just blurting out nonsense, though.

Re:You can't make C++ not ugly, but you can't not try (2010) by kllrnohj on Thursday February 27, 2020 @04:22PM (#22438059)
You made a broad, vague claim that iterator guarantees were broken. You misrepresented it as being a much larger issue that it actually is. Nearly all iterator guarantees are not broken. One very specific guarantee in one very specific case is, that's it. And it's a rare, not general, case at that, making the trade-off necessary to achieve it a bad default.
Re:You can't make C++ not ugly, but you can't not try (2010) by gpderetta on Friday February 28, 2020 @06:36AM (#22442084)
returning, moving, swapping a small vector would break any pointer to an element. That's a big deal. Interior pointers are used all the time (that's, more than performance, the primary reason that reserve exist).
Re:You can't make C++ not ugly, but you can't not try (2010) by leetcrew on Thursday February 27, 2020 @07:36AM (#22432675)
how do small vectors break iterator guarantees?
Re:You can't make C++ not ugly, but you can't not try (2010) by mehrdadn on Thursday February 27, 2020 @08:03AM (#22432830)
By invalidating iterators (and pointers and references) when swapping: https://stackoverflow.com/a/8191356
Re:You can't make C++ not ugly, but you can't not try (2010) by gpderetta on Thursday February 27, 2020 @07:58AM (#22432797)
Not sure about iterators, but they do break reference guarantees. Moving a vector doesn't invalidate pointers to the contained elements.