YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
intrusive_ptr.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <yaclib/config.hpp>
4
#include <
yaclib/util/ref.hpp
>
5
6
#include <type_traits>
7
8
namespace
yaclib
{
9
10
struct
NoRefTag
final
{};
11
12
/**
13
* A intrusive pointer to objects with an embedded reference count
14
*
15
* https://www.boost.org/doc/libs/1_77_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr
16
*/
17
template
<
typename
T>
18
class
YACLIB_TRIVIAL_ABI
IntrusivePtr
final
{
19
static_assert
(std::is_base_of_v<IRef, T>,
"T must be derived class of IRef"
);
20
21
public
:
22
using
Value
= T;
23
24
IntrusivePtr
()
noexcept
;
25
26
IntrusivePtr
(T*
other
)
noexcept
;
27
IntrusivePtr
(
IntrusivePtr
&&
other
)
noexcept
;
28
IntrusivePtr
(
const
IntrusivePtr
&
other
)
noexcept
;
29
30
IntrusivePtr
&
operator
=(T*
other
)
noexcept
;
31
IntrusivePtr
&
operator
=(
IntrusivePtr
&&
other
)
noexcept
;
32
IntrusivePtr
&
operator
=(
const
IntrusivePtr
&
other
)
noexcept
;
33
34
template
<
typename
U
>
35
IntrusivePtr
(
IntrusivePtr
<
U
>&&
other
)
noexcept
;
36
template
<
typename
U
>
37
IntrusivePtr
(
const
IntrusivePtr
<
U
>&
other
)
noexcept
;
38
39
template
<
typename
U
>
40
IntrusivePtr
&
operator
=(
IntrusivePtr
<
U
>&&
other
)
noexcept
;
41
template
<
typename
U
>
42
IntrusivePtr
&
operator
=(
const
IntrusivePtr
<
U
>&
other
)
noexcept
;
43
44
~
IntrusivePtr
()
noexcept
;
45
46
T* Get()
const
noexcept
;
47
T* Release()
noexcept
;
48
49
explicit
operator
bool
()
const
noexcept
;
50
51
T&
operator
*()
const
noexcept
;
52
T*
operator
->()
const
noexcept
;
53
54
void
Swap(
IntrusivePtr
&
other
)
noexcept
;
55
56
IntrusivePtr
(
NoRefTag
, T*
other
)
noexcept
;
57
void
Reset(
NoRefTag
, T*
other
)
noexcept
;
58
59
private
:
60
template
<
typename
U
>
61
friend
class
IntrusivePtr
;
62
63
T* _ptr;
64
};
65
66
template
<
typename
T,
typename
U
>
67
inline
bool
operator
==(
const
IntrusivePtr
<T>&
lhs
,
const
IntrusivePtr
<
U
>&
rhs
)
noexcept
{
68
return
lhs
.
Get
() ==
rhs
.Get();
69
}
70
71
template
<
typename
T,
typename
U>
72
inline
bool
operator!=
(
const
IntrusivePtr<T>
&
lhs
,
const
IntrusivePtr<U>
&
rhs
)
noexcept
{
73
return
lhs
.Get() !=
rhs
.Get();
74
}
75
76
template
<
typename
T,
typename
U>
77
inline
bool
operator==
(
const
IntrusivePtr<T>
&
lhs
,
U
*
rhs
)
noexcept
{
78
return
lhs
.Get() ==
rhs
;
79
}
80
81
template
<
typename
T,
typename
U>
82
inline
bool
operator!=
(
const
IntrusivePtr<T>
&
lhs
,
U
*
rhs
)
noexcept
{
83
return
lhs
.Get() !=
rhs
;
84
}
85
86
template
<
typename
T,
typename
U>
87
inline
bool
operator==
(T*
lhs
,
const
IntrusivePtr<U>
&
rhs
)
noexcept
{
88
return
lhs
==
rhs
.Get();
89
}
90
91
template
<
typename
T,
typename
U>
92
inline
bool
operator!=
(T*
lhs
,
const
IntrusivePtr<U>
&
rhs
)
noexcept
{
93
return
lhs
!=
rhs
.Get();
94
}
95
96
template
<
typename
T>
97
inline
bool
operator==
(
const
IntrusivePtr<T>
&
lhs
, std::nullptr_t)
noexcept
{
98
return
lhs
.Get() ==
nullptr
;
99
}
100
101
template
<
typename
T>
102
inline
bool
operator==
(std::nullptr_t,
const
IntrusivePtr<T>
&
rhs
)
noexcept
{
103
return
rhs
.Get() ==
nullptr
;
104
}
105
106
template
<
typename
T>
107
inline
bool
operator!=
(
const
IntrusivePtr<T>
&
lhs
, std::nullptr_t)
noexcept
{
108
return
lhs
.Get() !=
nullptr
;
109
}
110
111
template
<
typename
T>
112
inline
bool
operator!=
(std::nullptr_t,
const
IntrusivePtr<T>
&
rhs
)
noexcept
{
113
return
rhs
.Get() !=
nullptr
;
114
}
115
116
template
<
typename
T>
117
inline
bool
operator<
(
const
IntrusivePtr<T>
&
lhs
,
const
IntrusivePtr<T>
&
rhs
)
noexcept
{
118
return
lhs
.Get() <
rhs
.Get();
119
}
120
121
}
// namespace yaclib
122
123
#include <
yaclib/util/detail/intrusive_ptr_impl.hpp
>
yaclib::IntrusivePtr
A intrusive pointer to objects with an embedded reference count.
Definition
intrusive_ptr.hpp:18
yaclib::IntrusivePtr::Get
T * Get() const noexcept
Definition
intrusive_ptr_impl.hpp:78
yaclib::IntrusivePtr::Value
T Value
Definition
intrusive_ptr.hpp:22
intrusive_ptr_impl.hpp
yaclib
Definition
base_core.hpp:15
yaclib::MakeContract
Contract< V, T > MakeContract()
Creates related future and promise.
Definition
contract.hpp:25
yaclib::operator<
bool operator<(const IntrusivePtr< T > &lhs, const IntrusivePtr< T > &rhs) noexcept
Definition
intrusive_ptr.hpp:117
yaclib::operator==
bool operator==(const IntrusivePtr< T > &lhs, const IntrusivePtr< U > &rhs) noexcept
Definition
intrusive_ptr.hpp:67
yaclib::operator!=
bool operator!=(const IntrusivePtr< T > &lhs, const IntrusivePtr< U > &rhs) noexcept
Definition
intrusive_ptr.hpp:72
ref.hpp
yaclib::NoRefTag
Definition
intrusive_ptr.hpp:10
include
yaclib
util
intrusive_ptr.hpp
Generated by
1.9.8