]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/ref.h
import ceph quincy 17.2.4
[ceph.git] / 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
3
4 #ifndef COMMON_REF_H
5 #define COMMON_REF_H
6
7 #include <boost/intrusive_ptr.hpp>
8
9 namespace ceph {
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());
15 }
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};
19 }
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());
23 }
24 template<class T, typename... Args>
25 ceph::ref_t<T> make_ref(Args&&... args) {
26 return {new T(std::forward<Args>(args)...), false};
27 }
28 }
29
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)
33
34 #endif