YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
intrusive_ptr_impl.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/log.hpp>
4
5namespace yaclib {
6
7template <typename T>
10
11template <typename T>
13 if (_ptr) {
14 _ptr->IncRef();
15 }
16}
17
18template <typename T>
22
23template <typename T>
26
27template <typename T>
29 if (_ptr != other) {
30 IntrusivePtr{other}.Swap(*this);
31 }
32 return *this;
33}
35template <typename T>
37 Swap(other);
38 return *this;
39}
40
41template <typename T>
43 return operator=(other._ptr);
45
46template <typename T>
47template <typename U>
49 other._ptr = nullptr;
50}
52template <typename T>
53template <typename U>
56
57template <typename T>
58template <typename U>
60 IntrusivePtr{std::move(other)}.Swap(*this);
61 return *this;
62}
63
64template <typename T>
65template <typename U>
67 return operator=(other._ptr);
68}
69
70template <typename T>
72 if (_ptr) {
73 _ptr->DecRef();
74 }
75}
76
77template <typename T>
79 return _ptr;
80}
81
82template <typename T>
84 auto ptr = _ptr;
85 _ptr = nullptr;
86 return ptr;
87}
88
89template <typename T>
91 return _ptr != nullptr;
92}
93
94template <typename T>
96 YACLIB_ASSERT(_ptr != nullptr);
97 return *_ptr;
98}
99
100template <typename T>
102 YACLIB_ASSERT(_ptr != nullptr);
103 return _ptr;
104}
105
106template <typename T>
108 auto* ptr = _ptr;
109 _ptr = other._ptr;
110 other._ptr = ptr;
111}
112
113template <typename T>
116
117template <typename T>
119 _ptr = other;
120}
121
122} // namespace yaclib
A intrusive pointer to objects with an embedded reference count.
friend class IntrusivePtr
void Reset(NoRefTag, T *other) noexcept
T & operator*() const noexcept
T * operator->() const noexcept
void Swap(IntrusivePtr &other) noexcept
T * Get() const noexcept
IntrusivePtr & operator=(T *other) noexcept
#define YACLIB_ASSERT(cond)
Definition log.hpp:85
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25