Commit 09c88f59 authored by Dominik Charousset's avatar Dominik Charousset

Add access class for ADL-free intrusive_ptr types

The new access trait provides an alternative to the ADL interface for
cases where adding the free functions is undesired. In particular when
interfacing CAF with another 3rd party library or C libraries (that
would otherwise require users to clutter the global namespace).
parent a129f805
...@@ -17,6 +17,23 @@ ...@@ -17,6 +17,23 @@
namespace caf { namespace caf {
/// Policy for adding and releasing references in an @ref intrusive_ptr. The
/// default implementation dispatches to the free function pair
/// `intrusive_ptr_add_ref` and `intrusive_ptr_release` that the policy picks up
/// via ADL.
/// @relates intrusive_ptr
template <class T>
struct intrusive_ptr_access {
public:
static void add_ref(T* ptr) noexcept {
intrusive_ptr_add_ref(ptr);
}
static void release(T* ptr) noexcept {
intrusive_ptr_release(ptr);
}
};
/// An intrusive, reference counting smart pointer implementation. /// An intrusive, reference counting smart pointer implementation.
/// @relates ref_counted /// @relates ref_counted
template <class T> template <class T>
...@@ -76,7 +93,7 @@ public: ...@@ -76,7 +93,7 @@ public:
~intrusive_ptr() { ~intrusive_ptr() {
if (ptr_) if (ptr_)
intrusive_ptr_release(ptr_); intrusive_ptr_access<T>::release(ptr_);
} }
void swap(intrusive_ptr& other) noexcept { void swap(intrusive_ptr& other) noexcept {
...@@ -102,7 +119,7 @@ public: ...@@ -102,7 +119,7 @@ public:
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_access<T>::release(old);
} }
template <class... Ts> template <class... Ts>
...@@ -171,7 +188,7 @@ private: ...@@ -171,7 +188,7 @@ private:
void set_ptr(pointer raw_ptr, bool add_ref) noexcept { void set_ptr(pointer raw_ptr, bool add_ref) noexcept {
ptr_ = raw_ptr; ptr_ = raw_ptr;
if (raw_ptr && add_ref) if (raw_ptr && add_ref)
intrusive_ptr_add_ref(raw_ptr); intrusive_ptr_access<T>::add_ref(raw_ptr);
} }
pointer ptr_; pointer 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