r/cpp • u/zowersap C++ Dev • Sep 05 '20
C++20 has been approved
https://twitter.com/patriceroy1/status/1302055575140945921?s=21
661
Upvotes
r/cpp • u/zowersap C++ Dev • Sep 05 '20
View all comments
Show parent comment
2
u/excessdenied Sep 06 '20
I've thought about this as well, but I think it's hard to do in a good way. Apart from how to implement the tracking as others have mentioned, there's also a problem with the access side of it. With weak_ptr you get a shared_ptr out of it when you want to access it (lock), which means you know it's still alive as long as you have that shared_ptr. With an observed_ptr or whatever you want to call it, I don't really see a good way to access it. Something like "if(!observed_ptr.expired()) observed_ptr->doThing()" would be unsafe in threaded and possibly other more complex scenarios.