Commit fbba3248 authored by Dominik Charousset's avatar Dominik Charousset

Merge pull request #410 from Lingxi-Li/topic/intrusive_ptr

Improve `intrusive_ptr`
parents 0b167399 b95cc31e
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
namespace caf { namespace caf {
/// An intrusive, reference counting smart pointer impelementation. /// An intrusive, reference counting smart pointer implementation.
/// @relates ref_counted /// @relates ref_counted
template <class T> template <class T>
class intrusive_ptr : detail::comparable<intrusive_ptr<T>>, class intrusive_ptr : detail::comparable<intrusive_ptr<T>>,
...@@ -66,9 +66,8 @@ public: ...@@ -66,9 +66,8 @@ public:
} }
~intrusive_ptr() { ~intrusive_ptr() {
if (ptr_) { if (ptr_)
intrusive_ptr_release(ptr_); intrusive_ptr_release(ptr_);
}
} }
void swap(intrusive_ptr& other) noexcept { void swap(intrusive_ptr& other) noexcept {
...@@ -92,14 +91,8 @@ public: ...@@ -92,14 +91,8 @@ public:
void reset(pointer new_value = nullptr, bool add_ref = true) { void reset(pointer new_value = nullptr, bool add_ref = true) {
auto old = ptr_; auto old = ptr_;
set_ptr(new_value, add_ref); set_ptr(new_value, add_ref);
if (old) { if (old)
intrusive_ptr_release(old); intrusive_ptr_release(old);
}
}
template <class... Ts>
void emplace(Ts&&... xs) {
reset(new T(std::forward<Ts>(xs)...));
} }
intrusive_ptr& operator=(pointer ptr) { intrusive_ptr& operator=(pointer ptr) {
...@@ -107,24 +100,11 @@ public: ...@@ -107,24 +100,11 @@ public:
return *this; return *this;
} }
intrusive_ptr& operator=(intrusive_ptr&& other) { intrusive_ptr& operator=(intrusive_ptr other) {
swap(other); swap(other);
return *this; return *this;
} }
intrusive_ptr& operator=(const intrusive_ptr& other) {
intrusive_ptr tmp{other};
swap(tmp);
return *this;
}
template <class Y>
intrusive_ptr& operator=(intrusive_ptr<Y> other) {
intrusive_ptr tmp{std::move(other)};
swap(tmp);
return *this;
}
pointer get() const { pointer get() const {
return ptr_; return ptr_;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment