cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.16k stars 7.05k forks source link

Improvements to RefPtr<T>: #20681

Closed BodbDearg closed 2 years ago

BodbDearg commented 3 years ago

(1) Disable implicit conversion (by default) to a raw pointer as it may be very dangerous in certain situations. The conversion can be re-enabled for now if required, but it should eventually be removed. (2) Add 'RefPtr::make()' to make it easy to construct and return a new 'RefPtr' wrapped object. This works in a similar way to 'std::make_shared' and 'std::make_unique'. (3) Remove the static assert verifying the base class of the pointed-to type. This assert prevents 'RefPtr' from being used with forward referenced types in header interfaces and causes far more dependencies to be exposed via headers as a result. If the wrong type is used then the user will get compile errors anyway when the various template functions are instantiated.