4 ms·
Is a C++ std::span object like std::string_view in that it can outlive the data it points to? If yes, that's hardly an improvement over a raw C pointer/size pai
by flohofwoe 4y ago
Is a C++ std::span object like std::string_view in that it can outlive the data it points to? If yes, that's hardly an improvement over a raw C pointer/size pair.
- frozenport 4y agoIts an "input only" type, aka don't return it, but use it as an argument
- flohofwoe 4y agoThat's just by convention though, right? C++ doesn't prevent me from storing the std::span somewhere so that it outlives the scope of the called function? IMHO it's disappointing that C++ adds new memory management footguns without first fixing the basics (like at least some rudimentary lifetime tracking to help with such situations).
- bartwe 4y agoc# got this right, enforcing the lifetime of Span<>
- BenFrantzDale 4y agoI keep considering writing a `unique_span` and `shared_span`. Really `span` or (a type it’s based on) should have been templated on the pointer type, so a `span<shared_ptr<const T[]>>` for example.
- germandiago 4y agoYes, in C++ you can also do this: ``` int & a = *new int; ``` And it would be as stupid as juggling with spans around liberally.