3 ms·
I write c++ every day. Theres no such thing as "just never use a raw pointer", as existing code will use pointers, libraries become pointers, and there's no "no
by maccard 4y ago
I write c++ every day. Theres no such thing as "just never use a raw pointer", as existing code will use pointers, libraries become pointers, and there's no "non-owning" equivalent of a unique pointer. Even if there was:
- lifetimes are hard. The core guidelines recommend using span and string view, but correct usage of those isnt straightforward:
std::string_view make(const std::string& in)
{
return in;
}
Is not safe, at all. Span is also super dangerous:
std::vector<int> vec = {1, 2};
std::span<int> sp = vec;
vec.push-back(1);
Lambda capture semantics are another area where you might end up surprised by the behaviour too, (and by surprised, I mean you'll have memory issues).
Then there's all the normal stuff that still exists like slicing, lack of bounds checking, resource leaks because of improper inheritance use, data races, use-after-free issues. Sure these can be caught by a sanitizer with enough effort, but they still exist.