3 ms·
how do you observe data you don't own if you never use a raw pointer or reference? if you use shared ptr for this: 1. shared ptrs aren't made for this use cas
by dureuill 4y ago
how do you observe data you don't own if you never use a raw pointer or reference?
if you use shared ptr for this:
1. shared ptrs aren't made for this use case, they're for shared ownership
2. why using C++ at all if it means reducing its performance to an (atomatocally) performance counted language? Rust allows for much more performance with its safe borrowed references.
That also not what the CPP core guidelines, that are supposed to define modern C++, prescribe: For general use, take T* or T& arguments rather than smart pointers[0]. This rule incurs the risk of use after free if the returned reference is kept for too long by the caller. The rules for reference validity are non trivial (eg you returned a reference to an item of a vector, if you push into your vector you might invalidate the reference), so this is a significant source of bugs even in modern C++.
if you don't use shared ptr or references/pointers for this i'm curious as to which mechanism you're using to observe non owning data
[0]: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-smart https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines...