diff options
author | pavook <pavook@yandex-team.com> | 2024-11-04 18:22:23 +0300 |
---|---|---|
committer | pavook <pavook@yandex-team.com> | 2024-11-04 18:37:03 +0300 |
commit | a6181c673b1896aa2e0377c725ccc0bd23d0ebe9 (patch) | |
tree | 272fb016a928af28b416923ad75ae305e93a57ec /library/cpp | |
parent | 277ba0ca11143f8dde61dbf1778360eea6222ca1 (diff) | |
download | ydb-a6181c673b1896aa2e0377c725ccc0bd23d0ebe9.tar.gz |
add ::element_type, .get() to smart pointers for better compatibility with std
For example, this makes it possible to use gtest pointer matchers on smart pointers
commit_hash:2650074ae18ee35696b297d3d1f0393e7350789f
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/yt/memory/atomic_intrusive_ptr-inl.h | 6 | ||||
-rw-r--r-- | library/cpp/yt/memory/atomic_intrusive_ptr.h | 6 | ||||
-rw-r--r-- | library/cpp/yt/memory/intrusive_ptr.h | 9 | ||||
-rw-r--r-- | library/cpp/yt/memory/weak_ptr.h | 1 |
4 files changed, 22 insertions, 0 deletions
diff --git a/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h b/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h index e337a78bcf..ffb2aaff5f 100644 --- a/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h +++ b/library/cpp/yt/memory/atomic_intrusive_ptr-inl.h @@ -237,6 +237,12 @@ typename TAtomicIntrusivePtr<T>::TRawPtr TAtomicIntrusivePtr<T>::Get() const } template <class T> +typename TAtomicIntrusivePtr<T>::TRawPtr TAtomicIntrusivePtr<T>::get() const +{ + return Get(); +} + +template <class T> TPackedPtr TAtomicIntrusivePtr<T>::AcquireObject(T* obj, bool consumeRef) { if (obj) { diff --git a/library/cpp/yt/memory/atomic_intrusive_ptr.h b/library/cpp/yt/memory/atomic_intrusive_ptr.h index 4bab78ef58..243920bdab 100644 --- a/library/cpp/yt/memory/atomic_intrusive_ptr.h +++ b/library/cpp/yt/memory/atomic_intrusive_ptr.h @@ -20,6 +20,9 @@ template <class T> class TAtomicIntrusivePtr { public: + using TUnderlying = T; + using element_type = T; + TAtomicIntrusivePtr() = default; TAtomicIntrusivePtr(std::nullptr_t); @@ -45,6 +48,9 @@ public: //! Result is only suitable for comparison, not dereference. TRawPtr Get() const; + //! Result is only suitable for comparison, not dereference. + TRawPtr get() const; + explicit operator bool() const; private: diff --git a/library/cpp/yt/memory/intrusive_ptr.h b/library/cpp/yt/memory/intrusive_ptr.h index 91b15279ae..1a168cec0e 100644 --- a/library/cpp/yt/memory/intrusive_ptr.h +++ b/library/cpp/yt/memory/intrusive_ptr.h @@ -18,6 +18,9 @@ class TIntrusivePtr public: using TUnderlying = T; + //! For compatibility with std:: smart pointers. + using element_type = T; + constexpr TIntrusivePtr() noexcept { } @@ -148,6 +151,12 @@ public: return T_; } + //! Returns the pointer, for compatibility with std:: smart pointers. + T* get() const noexcept + { + return T_; + } + //! Returns the pointer and releases the ownership. T* Release() noexcept { diff --git a/library/cpp/yt/memory/weak_ptr.h b/library/cpp/yt/memory/weak_ptr.h index c647198aaf..e7b847653d 100644 --- a/library/cpp/yt/memory/weak_ptr.h +++ b/library/cpp/yt/memory/weak_ptr.h @@ -13,6 +13,7 @@ class TWeakPtr { public: using TUnderlying = T; + using element_type = T; //! Empty constructor. TWeakPtr() = default; |