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/util/ref.hpp>
4
5#include <type_traits>
6
7namespace yaclib {
8
9struct NoRefTag final {};
10
11/**
12 * A intrusive pointer to objects with an embedded reference count
13 *
14 * https://www.boost.org/doc/libs/1_77_0/libs/smart_ptr/doc/html/smart_ptr.html#intrusive_ptr
15 */
16template <typename T>
64
67 return lhs.Get() == rhs.Get();
68}
69
70template <typename T, typename U>
71inline bool operator!=(const IntrusivePtr<T>& lhs, const IntrusivePtr<U>& rhs) noexcept {
72 return lhs.Get() != rhs.Get();
73}
74
75template <typename T, typename U>
76inline bool operator==(const IntrusivePtr<T>& lhs, U* rhs) noexcept {
77 return lhs.Get() == rhs;
78}
79
80template <typename T, typename U>
81inline bool operator!=(const IntrusivePtr<T>& lhs, U* rhs) noexcept {
82 return lhs.Get() != rhs;
83}
84
85template <typename T, typename U>
86inline bool operator==(T* lhs, const IntrusivePtr<U>& rhs) noexcept {
87 return lhs == rhs.Get();
88}
89
90template <typename T, typename U>
91inline bool operator!=(T* lhs, const IntrusivePtr<U>& rhs) noexcept {
92 return lhs != rhs.Get();
93}
94
95template <typename T>
96inline bool operator==(const IntrusivePtr<T>& lhs, std::nullptr_t) noexcept {
97 return lhs.Get() == nullptr;
98}
99
100template <typename T>
101inline bool operator==(std::nullptr_t, const IntrusivePtr<T>& rhs) noexcept {
102 return rhs.Get() == nullptr;
103}
104
105template <typename T>
106inline bool operator!=(const IntrusivePtr<T>& lhs, std::nullptr_t) noexcept {
107 return lhs.Get() != nullptr;
108}
109
110template <typename T>
111inline bool operator!=(std::nullptr_t, const IntrusivePtr<T>& rhs) noexcept {
112 return rhs.Get() != nullptr;
113}
114
115template <typename T>
116inline bool operator<(const IntrusivePtr<T>& lhs, const IntrusivePtr<T>& rhs) noexcept {
117 return lhs.Get() < rhs.Get();
118}
119
120} // namespace yaclib
121
A intrusive pointer to objects with an embedded reference count.
friend class IntrusivePtr
void Reset(NoRefTag, T *other) noexcept
void Swap(IntrusivePtr &other) noexcept
T * Get() const noexcept
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
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25