How to add a (hacky) borrow checker to C++: 1/6
-
-
Replying to @fitzgen
In DEBUG builds, add a `borrow_count` member to `std::unique_ptr`, 2/6
1 reply 1 retweet 0 likes -
Replying to @fitzgen
Define `std::borrowed_ptr` which is just wraps a plain old raw ptr in non-DEBUG builds. 3/6
2 replies 1 retweet 0 likes -
Replying to @fitzgen
However, in DEBUG builds, add a `std::unique_ptr&` member. Ctor increments member's `borrow_count`, dtor decrements it. 4/6
1 reply 1 retweet 0 likes -
Replying to @fitzgen
Finally, `std::unique_ptr`'s dtor asserts that its `borrow_count` is 0, in DEBUG builds. 5/6
1 reply 1 retweet 1 like -
Replying to @fitzgen
Extending with const and mut borrows is an exercise left to the reader. Fin. 6/6
1 reply 0 retweets 0 likes -
Replying to @fitzgen
How is `borrowed_ptr` better than using `std::unique_ptr&`? 7/6
2 replies 1 retweet 0 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.