3 ms·
No, they do not: * Dangling references from lambda captures are no different than dangling references or pointers passed without lambdas, and not more likely t
by einpoklum 6y ago
No, they do not:
* Dangling references from lambda captures are no different than dangling references or pointers passed without lambdas, and not more likely to be used.
* spans are no worse, and usually better, than using a raw pointer and a size; they don't make memory errors more likely.
* string_view - indeed, it potentially introduces a dangling pointer. But - that only happens if you store it. Which is why I qualified my claim to "using recommended idioms". If you replace your `const char*` or `const std::string&` with `std::string_view` you have not introduced a potential memory error.
More generally - new language/library construct which do not manage their own memory can introduce memory errors. But, luckily, C++ now has a better "harness" of protecting you from many of these without costing you and performance nor introducing now memory issues.
So I stand by my claim. Having said that - C++ is not a safety-guaranteed language, and if that's what you need then it is indeed not the language to use.