MCPcopy Create free account
hub / github.com/ceph/ceph / alloc_ptr

Class alloc_ptr

src/include/alloc_ptr.h:22–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20
21template <class T>
22class alloc_ptr
23{
24public:
25 typedef typename std::pointer_traits< std::unique_ptr<T> >::pointer pointer;
26 typedef typename std::pointer_traits< std::unique_ptr<T> >::element_type element_type;
27
28 alloc_ptr() : ptr() {}
29
30 template<class U>
31 alloc_ptr(U&& u) : ptr(std::forward<U>(u)) {}
32
33 alloc_ptr(alloc_ptr<pointer>&& rhs) : ptr(std::move(rhs.ptr)) {}
34 alloc_ptr(const alloc_ptr<pointer>& rhs) = delete;
35 alloc_ptr& operator=(const alloc_ptr<pointer>&& rhs) {
36 ptr = rhs.ptr;
37 }
38 alloc_ptr& operator=(const alloc_ptr<pointer>& rhs) {
39 ptr = rhs.ptr;
40 }
41
42 void swap (alloc_ptr<pointer>& rhs) {
43 ptr.swap(rhs.ptr);
44 }
45 element_type* release() {
46 return ptr.release();
47 }
48 void reset(element_type *p = nullptr) {
49 ptr.reset(p);
50 }
51 element_type* get() const {
52 if (!ptr)
53 ptr.reset(new element_type);
54 return ptr.get();
55 }
56 element_type& operator*() const {
57 if (!ptr)
58 ptr.reset(new element_type);
59 return *ptr;
60 }
61 element_type* operator->() const {
62 if (!ptr)
63 ptr.reset(new element_type);
64 return ptr.get();
65 }
66 operator bool() const {
67 return !!ptr;
68 }
69
70 friend bool operator< (const alloc_ptr& lhs, const alloc_ptr& rhs) {
71 return std::less<element_type>(*lhs, *rhs);
72 }
73 friend bool operator<=(const alloc_ptr& lhs, const alloc_ptr& rhs) {
74 return std::less_equal<element_type>(*lhs, *rhs);
75 }
76 friend bool operator> (const alloc_ptr& lhs, const alloc_ptr& rhs) {
77 return std::greater<element_type>(*lhs, *rhs);
78 }
79 friend bool operator>=(const alloc_ptr& lhs, const alloc_ptr& rhs) {

Callers

nothing calls this directly

Calls 1

resetMethod · 0.45

Tested by

no test coverage detected