|
|
|
|
|
by duneroadrunner
3120 days ago
|
|
> good coding conventions in C++ will get you 90% of the way there For those that need it, SaferCPlusPlus conventions will get you even further. > Basically in C++ I think an of old-style pointers/refs as Rust-like "borrowed" references. They key safety feature of Rust references is that they have "scope lifetime" and their target is guaranteed to be alive for the duration of that scope lifetime. You can use SaferCPlusPlus' "scope pointers"[1] to achieve this in C++. Scope pointers can be explicitly converted to raw pointers, so they can be used with existing "legacy" functions. But you get even more benefit when you change your function interfaces to support scope pointers directly[2]. For example, it would prevent the function from (inappropriately) putting a copy of the scope pointer into "long term storage" (like Rust does). [1] shameless plug: https://github.com/duneroadrunner/SaferCPlusPlus#scope-point... [2] https://github.com/duneroadrunner/SaferCPlusPlus#safely-pass... |
|