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
8namespace yaclib {
9
10struct 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 */
17template <typename T>
65
68 return lhs.Get() == rhs.Get();
69}
70
71template <typename T, typename U>
72inline bool operator!=(const IntrusivePtr<T>& lhs, const IntrusivePtr<U>& rhs) noexcept {
73 return lhs.Get() != rhs.Get();
74}
75
76template <typename T, typename U>
77inline bool operator==(const IntrusivePtr<T>& lhs, U* rhs) noexcept {
78 return lhs.Get() == rhs;
79}
80
81template <typename T, typename U>
82inline bool operator!=(const IntrusivePtr<T>& lhs, U* rhs) noexcept {
83 return lhs.Get() != rhs;
84}
85
86template <typename T, typename U>
87inline bool operator==(T* lhs, const IntrusivePtr<U>& rhs) noexcept {
88 return lhs == rhs.Get();
89}
90
91template <typename T, typename U>
92inline bool operator!=(T* lhs, const IntrusivePtr<U>& rhs) noexcept {
93 return lhs != rhs.Get();
94}
95
96template <typename T>
97inline bool operator==(const IntrusivePtr<T>& lhs, std::nullptr_t) noexcept {
98 return lhs.Get() == nullptr;
99}
100
101template <typename T>
102inline bool operator==(std::nullptr_t, const IntrusivePtr<T>& rhs) noexcept {
103 return rhs.Get() == nullptr;
104}
105
106template <typename T>
107inline bool operator!=(const IntrusivePtr<T>& lhs, std::nullptr_t) noexcept {
108 return lhs.Get() != nullptr;
109}
110
111template <typename T>
112inline bool operator!=(std::nullptr_t, const IntrusivePtr<T>& rhs) noexcept {
113 return rhs.Get() != nullptr;
114}
115
116template <typename T>
117inline bool operator<(const IntrusivePtr<T>& lhs, const IntrusivePtr<T>& rhs) noexcept {
118 return lhs.Get() < rhs.Get();
119}
120
121} // namespace yaclib
122
A intrusive pointer to objects with an embedded reference count.
T * Get() const noexcept
Contract< V, T > MakeContract()
Creates related future and promise.
Definition contract.hpp:25
bool operator<(const IntrusivePtr< T > &lhs, const IntrusivePtr< T > &rhs) noexcept
bool operator==(const IntrusivePtr< T > &lhs, const IntrusivePtr< U > &rhs) noexcept
bool operator!=(const IntrusivePtr< T > &lhs, const IntrusivePtr< U > &rhs) noexcept