]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/ref.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
7 #include <boost/intrusive_ptr.hpp>
10 template<typename T
> using ref_t
= boost::intrusive_ptr
<T
>;
11 template<typename T
> using cref_t
= boost::intrusive_ptr
<const T
>;
12 template<class T
, class U
>
13 ref_t
<T
> ref_cast(const ref_t
<U
>& r
) noexcept
{
14 return static_cast<T
*>(r
.get());
16 template<class T
, class U
>
17 ref_t
<T
> ref_cast(ref_t
<U
>&& r
) noexcept
{
18 return {static_cast<T
*>(r
.detach()), false};
20 template<class T
, class U
>
21 cref_t
<T
> ref_cast(const cref_t
<U
>& r
) noexcept
{
22 return static_cast<const T
*>(r
.get());
24 template<class T
, typename
... Args
>
25 ceph::ref_t
<T
> make_ref(Args
&&... args
) {
26 return {new T(std::forward
<Args
>(args
)...), false};
30 // Friends cannot be partial specializations: https://en.cppreference.com/w/cpp/language/friend
31 #define FRIEND_MAKE_REF(C) \
32 template<class T, typename... Args> friend ceph::ref_t<T> ceph::make_ref(Args&&... args)