4 ms·
> But std::vector isn't legacy Oh yes it is. std::vector is hella legacy. That's not a C++11 addition (where "Modern C++" began). And it has all sorts of very-
by kllrnohj 4y ago
> But std::vector isn't legacy
Oh yes it is. std::vector is hella legacy. That's not a C++11 addition (where "Modern C++" began). And it has all sorts of very-legacy warts like https://en.cppreference.com/w/cpp/container/vector_bool https://en.cppreference.com/w/cpp/container/vector_bool
"Modern C++" added std::array which is what you might be thinking of, but it's much more limited & targets a different usage.
- pornel 4y agoYou can't be serious. "Don't use std::vector" is the modern C++ recommendation now? If it is, it should throw a warning that it's deprecated and have a replacement for it.
- kllrnohj 4y agoI didn't say it wasn't recommended or should be avoided, but it definitely has "legacy" to it. It's not an exclusively "Modern C++" container.
- SleepyMyroslav 4y agoif you are interested in C++ usage ... then you might learn that vector is the only std container that is relevant in modern context. Because other have not aged well. String is heavily optimized for single short size. Which is almost never a tradeoff that matches your size. Hash things are strictly worse in std. Node based with allocator are not for high performance. Of course people use additional array types that have short buffer sizes that are needed and such. But vector is probably the last usable std container. Gaming where i work has some extra requirements that exclude even vector but i think i gave you overview.
- kllrnohj 4y agoI use vector all the time, but that doesn't mean it's without any legacy baggage. It didn't get a clean sheet reboot in "Modern C++" The argument was "this bug exists in pop_back, therefore Modern C++ is a failure" which is nonsense. This pop_back behavior predates "Modern C++", so it cannot be used as a reflection upon the current trends.
- tialaramex 4y agoIt doesn't really matter when you pick. Every era of "Modern C++" has enough unsafety to judge it a failure unless unsafety was the goal. Take std::span which didn't even exist until C++ 20. Surely that's a modern feature and is safe by design right? Who would add a feature to a language they wanted to be safer five years after Rust and yet make it unsafe by default and even remove safer options "for compatibility" ? Ah yes, WG21.
- pjmlp 4y agoI was so let down by that. Surely after Microsoft being advocating for span across C++ and C#, based on their Midori experience, C++ would adopt it as safe by default, nope. The scenarios where there is no option in tooling (C vs C++ as only options), we have to keep using C++, for others, we can replace one domino piece at a time, eventually only those niche scenarios will be left.
- dureuill 4y agoI don't follow. What should one use to have safe and efficient dynamically growable arrays in modern C++ if `std::vector` is not considered as modern?
- xigoi 4y agoWhat good is it that a feature is legacy if there's no replacement for it?