From ecc0e9cf254df832d394d67798a092ad9620317a Mon Sep 17 00:00:00 2001 From: Nomango <569629550@qq.com> Date: Sun, 20 Jan 2019 12:07:59 +0800 Subject: [PATCH] add: SmartMaker & NEW macro --- core/base/intrusive/SmartPointer.hpp | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/core/base/intrusive/SmartPointer.hpp b/core/base/intrusive/SmartPointer.hpp index 2900fdb7..e680501f 100644 --- a/core/base/intrusive/SmartPointer.hpp +++ b/core/base/intrusive/SmartPointer.hpp @@ -191,12 +191,6 @@ namespace easy2d } } - template - inline intrusive::SmartPointer MakeSmart(T* ptr) E2D_NOEXCEPT - { - return intrusive::SmartPointer(ptr); - } - // template class cannot specialize std::swap, // so implement a swap function in easy2d namespace template @@ -204,4 +198,27 @@ namespace easy2d { lhs.Swap(rhs); } + + class SmartMaker + { + public: + static inline SmartMaker const& Instance() + { + static SmartMaker maker; + return maker; + } + + template + inline intrusive::SmartPointer operator -(T* ptr) const + { + return intrusive::SmartPointer(ptr); + } + }; + +#ifdef NEW +# undef NEW +#endif + +#define NEW ::easy2d::SmartMaker::Instance() - new (std::nothrow) + }