diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/aloptional.h | 4 | ||||
-rw-r--r-- | common/intrusive_ptr.h | 10 |
2 files changed, 10 insertions, 4 deletions
diff --git a/common/aloptional.h b/common/aloptional.h index 79827482..269cba0e 100644 --- a/common/aloptional.h +++ b/common/aloptional.h @@ -9,7 +9,7 @@ namespace al { -#define REQUIRES(...) bool _rt=true, typename std::enable_if<_rt && (__VA_ARGS__),int>::type = 0 +#define REQUIRES(...) bool rt_=true, typename std::enable_if<rt_ && (__VA_ARGS__),bool>::type = true struct nullopt_t { }; struct in_place_t { }; @@ -61,7 +61,7 @@ public: !std::is_constructible<U&&, T>::value)> constexpr optional(U&& value) : mHasValue{true}, mValue{std::forward<U>(value)} { } - ~optional() { reset(); } + ~optional() { if(mHasValue) al::destroy_at(std::addressof(mValue)); } optional& operator=(nullopt_t) noexcept { reset(); return *this; } template<REQUIRES(std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value)> diff --git a/common/intrusive_ptr.h b/common/intrusive_ptr.h index fa76ad48..595c831d 100644 --- a/common/intrusive_ptr.h +++ b/common/intrusive_ptr.h @@ -56,7 +56,7 @@ public: { rhs.mPtr = nullptr; } intrusive_ptr(std::nullptr_t) noexcept { } explicit intrusive_ptr(T *ptr) noexcept : mPtr{ptr} { } - ~intrusive_ptr() { reset(); } + ~intrusive_ptr() { if(mPtr) mPtr->release(); } intrusive_ptr& operator=(const intrusive_ptr &rhs) noexcept { @@ -66,7 +66,13 @@ public: return *this; } intrusive_ptr& operator=(intrusive_ptr&& rhs) noexcept - { std::swap(mPtr, rhs.mPtr); return *this; } + { + if(mPtr) + mPtr->release(); + mPtr = rhs.mPtr; + rhs.mPtr = nullptr; + return *this; + } operator bool() const noexcept { return mPtr != nullptr; } |