diff options
| author | Alexander Smirnov <[email protected]> | 2025-01-17 00:21:19 +0000 | 
|---|---|---|
| committer | Alexander Smirnov <[email protected]> | 2025-01-17 00:21:19 +0000 | 
| commit | 5b719379cf1aade381b1eddac735db7cdffd2840 (patch) | |
| tree | 92ba1f1a1e0fdfe4a7c6db9bea512ad9a25b8475 /library/cpp | |
| parent | 32f057a236ff37b9eb3ccbaee7da19dbaf487cc5 (diff) | |
| parent | 2f3fd95aac24e27a3b0aa2badda49db82bf36cc5 (diff) | |
Merge branch 'rightlib' into merge-libs-250117-0020
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/yt/memory/chunked_memory_allocator.h | 2 | ||||
| -rw-r--r-- | library/cpp/yt/memory/chunked_memory_pool-inl.h | 2 | ||||
| -rw-r--r-- | library/cpp/yt/memory/ref-inl.h | 14 | ||||
| -rw-r--r-- | library/cpp/yt/misc/concepts.h | 17 | ||||
| -rw-r--r-- | library/cpp/yt/threading/atomic_object.h | 2 | 
5 files changed, 28 insertions, 9 deletions
diff --git a/library/cpp/yt/memory/chunked_memory_allocator.h b/library/cpp/yt/memory/chunked_memory_allocator.h index d5e56c9f706..372fa5ce7e2 100644 --- a/library/cpp/yt/memory/chunked_memory_allocator.h +++ b/library/cpp/yt/memory/chunked_memory_allocator.h @@ -32,7 +32,7 @@ public:              maxSmallBlockSizeRatio,              GetRefCountedTypeCookie<TTag>())      { -        static_assert(sizeof(TTag) <= 1); +        static_assert(IsEmptyClass<TTag>());      }      //! Allocates #sizes bytes without any alignment. diff --git a/library/cpp/yt/memory/chunked_memory_pool-inl.h b/library/cpp/yt/memory/chunked_memory_pool-inl.h index 0faad070e9c..c6ed21fbac1 100644 --- a/library/cpp/yt/memory/chunked_memory_pool-inl.h +++ b/library/cpp/yt/memory/chunked_memory_pool-inl.h @@ -72,7 +72,7 @@ inline TChunkedMemoryPool::TChunkedMemoryPool(          GetRefCountedTypeCookie<TTag>(),          startChunkSize)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());  }  inline char* TChunkedMemoryPool::AllocateUnaligned(size_t size) diff --git a/library/cpp/yt/memory/ref-inl.h b/library/cpp/yt/memory/ref-inl.h index 62a0a4e6b4b..1658bce83cf 100644 --- a/library/cpp/yt/memory/ref-inl.h +++ b/library/cpp/yt/memory/ref-inl.h @@ -4,6 +4,8 @@  #include "ref.h"  #endif +#include <library/cpp/yt/misc/concepts.h> +  namespace NYT {  //////////////////////////////////////////////////////////////////////////////// @@ -134,7 +136,7 @@ Y_FORCE_INLINE TSharedRef::operator TRef() const  template <class TTag>  Y_FORCE_INLINE TSharedRef TSharedRef::FromString(TString str)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return FromString(std::move(str), GetRefCountedTypeCookie<TTag>());  } @@ -146,7 +148,7 @@ Y_FORCE_INLINE TSharedRef TSharedRef::FromString(TString str)  template <class TTag>  Y_FORCE_INLINE TSharedRef TSharedRef::FromString(std::string str)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return FromString(std::move(str), GetRefCountedTypeCookie<TTag>());  } @@ -163,7 +165,7 @@ Y_FORCE_INLINE TStringBuf TSharedRef::ToStringBuf() const  template <class TTag>  Y_FORCE_INLINE TSharedRef TSharedRef::MakeCopy(TRef ref)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return MakeCopy(ref, GetRefCountedTypeCookie<TTag>());  } @@ -227,7 +229,7 @@ Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t s  template <class TTag>  Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::MakeCopy(TRef ref)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return MakeCopy(ref, GetRefCountedTypeCookie<TTag>());  } @@ -247,14 +249,14 @@ Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::Slice(void* begin, void* end  template <class TTag>  Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::Allocate(size_t size, TSharedMutableRefAllocateOptions options)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return Allocate(size, options, GetRefCountedTypeCookie<TTag>());  }  template <class TTag>  Y_FORCE_INLINE TSharedMutableRef TSharedMutableRef::AllocatePageAligned(size_t size, TSharedMutableRefAllocateOptions options)  { -    static_assert(sizeof(TTag) <= 1); +    static_assert(IsEmptyClass<TTag>());      return AllocatePageAligned(size, options, GetRefCountedTypeCookie<TTag>());  } diff --git a/library/cpp/yt/misc/concepts.h b/library/cpp/yt/misc/concepts.h index eda0bc163f5..61a722d6d65 100644 --- a/library/cpp/yt/misc/concepts.h +++ b/library/cpp/yt/misc/concepts.h @@ -30,6 +30,15 @@ public:          (!NoExcept || IsNoThrowInvocable_);  }; +template <class T> +struct TIsEmpty +    : public T +{ +    int Dummy; + +    static constexpr bool Value = (sizeof(TIsEmpty) == sizeof(int)); +}; +  } // namespace NDetail  //////////////////////////////////////////////////////////////////////////////// @@ -81,4 +90,12 @@ concept CMutableRawPtr = CRawPtr<T> && !CConstRawPtr<T>;  //////////////////////////////////////////////////////////////////////////////// +template <class T> +constexpr bool IsEmptyClass() +{ +    return NDetail::TIsEmpty<T>::Value; +} + +//////////////////////////////////////////////////////////////////////////////// +  } // namespace NYT diff --git a/library/cpp/yt/threading/atomic_object.h b/library/cpp/yt/threading/atomic_object.h index 232a567e2dc..8b642c0f4fb 100644 --- a/library/cpp/yt/threading/atomic_object.h +++ b/library/cpp/yt/threading/atomic_object.h @@ -26,7 +26,7 @@ public:      template <class U>      T Exchange(U&& u); -    //! Atomically checks if then current value equals #expected. +    //! Atomically checks if the current value equals to #expected.      //! If so, replaces it with #desired and returns |true|.      //! Otherwise, copies it into #expected and returns |false|.      bool CompareExchange(T& expected, const T& desired);  | 
