4#ifndef _Stroika_Foundation_Memory_SharedPtr_h_
5#define _Stroika_Foundation_Memory_SharedPtr_h_ 1
7#include "Stroika/Foundation/StroikaPreComp.h"
14#include "Stroika/Foundation/Common/Common.h"
19_DeprecatedFile_ (
"Use shared_ptr instead");
21namespace Stroika::Foundation::Memory {
23 DISABLE_COMPILER_MSC_WARNING_START (4996);
24 DISABLE_COMPILER_GCC_WARNING_START (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
25 DISABLE_COMPILER_CLANG_WARNING_START (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
27 struct [[deprecated (
"Since Stroika v3, this is deprecated, and will go away - use shared_ptr")]] SharedPtrBase {
31 using ReferenceCountType =
unsigned int;
36 struct ReferenceCounterContainerType_ {
37 atomic<SharedPtrBase::ReferenceCountType> fCount;
39 ReferenceCounterContainerType_ ();
40 ReferenceCounterContainerType_ (
const ReferenceCounterContainerType_&) =
delete;
41 ReferenceCounterContainerType_ (
bool deleteCounter);
42 ReferenceCounterContainerType_& operator= (
const ReferenceCounterContainerType_&) =
delete;
47 class [[deprecated (
"Since Stroika v3, this is deprecated, and will go away - use shared_ptr")]] enable_shared_from_this;
55 class [[deprecated (
"Since Stroika v3, this is deprecated, and will go away - use shared_ptr")]] SharedPtr :
public SharedPtrBase {
57 using element_type = T;
60 using Envelope_ = Private_::Envelope_<T>;
65 SharedPtr () noexcept;
66 SharedPtr (nullptr_t) noexcept;
67 template <typename T2, enable_if_t<is_convertible_v<T2*, T*>>* =
nullptr>
68 explicit SharedPtr (T2* from);
69 SharedPtr (const SharedPtr& from) noexcept;
70 SharedPtr (SharedPtr&& from) noexcept;
71 template <typename T2, enable_if_t<is_convertible_v<T2*, T*>>* =
nullptr>
72 SharedPtr (const SharedPtr<T2>& from) noexcept;
73 template <typename T2, enable_if_t<is_convertible_v<T2*, T*>>* =
nullptr>
74 SharedPtr (SharedPtr<T2>&& from) noexcept;
77 explicit SharedPtr (const Envelope_& from) noexcept;
80 template <typename T2>
81 static Envelope_ mkEnvelope_ (T2* from, enable_if_t<is_convertible_v<T2*, Private_::ReferenceCounterContainerType_*>>* =
nullptr);
82 template <typename T2>
83 static Envelope_ mkEnvelope_ (T2* from, enable_if_t<!is_convertible_v<T2*, Private_::ReferenceCounterContainerType_*>>* =
nullptr);
86 nonvirtual SharedPtr& operator= (const SharedPtr& rhs) noexcept;
87 nonvirtual SharedPtr& operator= (SharedPtr&& rhs) noexcept;
95 nonvirtual
bool IsNull () const noexcept;
102 nonvirtual T& GetRep () const noexcept;
108 nonvirtual T* operator->() const noexcept;
113 nonvirtual T& operator* () const noexcept;
119 nonvirtual operator T* () const noexcept;
126 nonvirtual T* get () const noexcept;
136 nonvirtual
void release () noexcept;
142 nonvirtual
void clear () noexcept;
150 nonvirtual
void reset (T* p =
nullptr);
159 template <typename T2>
160 nonvirtual SharedPtr<T2> Dynamic_Cast () const noexcept;
165 nonvirtual
void swap (SharedPtr& rhs);
171 nonvirtual
bool IsUnique () const noexcept;
177 nonvirtual
bool unique () const noexcept;
185 nonvirtual ReferenceCountType CurrentRefCount () const noexcept;
191 nonvirtual ReferenceCountType use_count () const noexcept;
196 constexpr
bool operator== (const SharedPtr& rhs) const;
197 constexpr
bool operator== (nullptr_t) const;
202 constexpr strong_ordering operator<=> (const SharedPtr& rhs) const;
208 nonvirtual explicit operator
bool () const noexcept;
211 Envelope_ fEnvelope_;
214 template <typename T2>
215 friend class SharedPtr;
218 template <typename T2>
219 friend class enable_shared_from_this;
242 template <typename T>
257 nonvirtual SharedPtr<T> shared_from_this ();
260 template <
typename T2>
261 friend class SharedPtr;
302 template <
typename TO_TYPE_T,
typename FROM_TYPE_T>
303 Stroika::Foundation::Memory::SharedPtr<TO_TYPE_T> dynamic_pointer_cast (
const Stroika::Foundation::Memory::SharedPtr<FROM_TYPE_T>& sp)
noexcept;
308 template <
typename T>
309 Stroika::Foundation::Memory::SharedPtr<T> atomic_load (
const Stroika::Foundation::Memory::SharedPtr<T>* copyFrom);
310 template <
typename T>
311 Stroika::Foundation::Memory::SharedPtr<T> atomic_load_explicit (
const Stroika::Foundation::Memory::SharedPtr<T>* copyFrom, memory_order);
316 template <
typename T>
317 void atomic_store (Stroika::Foundation::Memory::SharedPtr<T>* storeTo, Stroika::Foundation::Memory::SharedPtr<T> o);
318 template <
typename T>
319 void atomic_store_explicit (Stroika::Foundation::Memory::SharedPtr<T>* storeTo, Stroika::Foundation::Memory::SharedPtr<T> o, memory_order);
323DISABLE_COMPILER_MSC_WARNING_END (4996);
324DISABLE_COMPILER_GCC_WARNING_END (
"GCC diagnostic ignored \"-Wdeprecated-declarations\"");
325DISABLE_COMPILER_CLANG_WARNING_END (
"clang diagnostic ignored \"-Wdeprecated-declarations\"");
334#include "SharedPtr.inl"
constexpr bool kSharedPtr_IsFasterThan_shared_ptr