From 487d344233205300e1ef3d9f484ceef94c4657fd Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Tue, 13 Aug 2019 09:15:56 -0700 Subject: [PATCH] common: add make_ref factory for RefCountedObject Signed-off-by: Patrick Donnelly --- src/common/ref.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common/ref.h b/src/common/ref.h index 6f3f7fd0b036b..055c9a07a0bac 100644 --- a/src/common/ref.h +++ b/src/common/ref.h @@ -10,17 +10,25 @@ namespace ceph { template using ref_t = boost::intrusive_ptr; template using cref_t = boost::intrusive_ptr; template -boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { +ref_t ref_cast(const ref_t& r) noexcept { return static_cast(r.get()); } template -boost::intrusive_ptr ref_cast(boost::intrusive_ptr&& r) noexcept { +ref_t ref_cast(ref_t&& r) noexcept { return {static_cast(r.detach()), false}; } template -boost::intrusive_ptr ref_cast(const boost::intrusive_ptr& r) noexcept { +cref_t ref_cast(const cref_t& r) noexcept { return static_cast(r.get()); } +template +ceph::ref_t make_ref(Args&&... args) { + return {new T(std::forward(args)...), false}; } +} + +// Friends cannot be partial specializations: https://en.cppreference.com/w/cpp/language/friend +#define FRIEND_MAKE_REF(C) \ +template friend ceph::ref_t ceph::make_ref(Args&&... args) #endif -- 2.39.5