3 ms·
vector.at() is memory safe. You get a choice. Easy to ban [] if you cannot statically prove it is safe. C++11 isn't the most memory safe language, but C++11
by bluGill 3y ago
vector.at() is memory safe. You get a choice. Easy to ban [] if you cannot statically prove it is safe.
C++11 isn't the most memory safe language, but C++11 is a lot safer than older versions, and C++23 is better yet. I'm expecting true memory safety in C++26 (time will tell), but it will be opt-in profiles which isn't ideal.
- z_open 3y agoThis is not idiomatic C++ in any C++ standard. You can also just replace vector with map so the brackets insert, but that isn't either.
- bluGill 3y agoPrefer at to [] is standard where I write C++. map is not standard because vector is almost always much faster random access in the real world (that is n is normally small enough that a linear search is faster than a binary search because of caching)