Ownership/Lifetimes
Hello, I saw you ask for feedback on Reddit and I don’t have an account so sharing it here.
This is where I have gotten stuck with the ideas of tracking lifetimes and without changing C++. Maybe you can see alternatives.
https://sunny.garden/@blinkygal/109846557503442563
Hello,
Unfortunately, I don't have an account in Mastodon, so will write here(hope the message will be delivered). First of all thanks for your comment, thanks to you it was easier for me to understand and implement the class Owner which tracks lifetime. I also read your article which is on the google page, it was very interesting. Thanks for the hint about the implementation of the ownership, I have an "almost similar" solution, of course not ideal, and maybe I am avoiding some of the rules that are laid down in the Rust language, but at least I more or less understood the idea that was originally laid down in the Rust language.
P.S.
I thought before to track lifetime through the memory using unique_ptr or shared_ptr or even more dive in and use some functions for controlling memory from C but I realize that it's too complicated to track after. I also believe that the real implementation of the borrow checker can be rewritten in some parts of the code in the compiler itself or by creating new annotations that are again sewn into the compiler (such as clang).
Most likely I think that such an opportunity will appear in the annotations. I will also leave here Herb Sutter's article about Lifetime perhaps in his proposed cpp2 there will be such or in the new version of C++.
P.P.S
I have a very rough implementation, but if you're interested, it is in the v2.h file. I will figure out how I can improve my solution maybe a stateful template will help or static_assert, of course, it's not a real implementation but some advantages can be.
Local analysis has been poked at a lot. I would love to see a solution that provides exclusivity across functions, while keeping the analysis local to each function (so it can scale and stay understandable).
Have you seen crubit's lifetime annotations ideas btw? Maybe you will find some inspiration there.
https://github.com/google/crubit/blob/main/docs/lifetime_annotations_cpp.md