Browse Source

PoolAllocator::New only for derived from TObjectBase

danilalexeev 1 year ago
parent
commit
09ac62184d
2 changed files with 11 additions and 11 deletions
  1. 1 1
      yt/yt/core/misc/pool_allocator-inl.h
  2. 10 10
      yt/yt/core/misc/pool_allocator.h

+ 1 - 1
yt/yt/core/misc/pool_allocator-inl.h

@@ -64,7 +64,7 @@ inline void TPoolAllocator::Free(void* ptr) noexcept
     header->Pool->DoFree(ptr);
 }
 
-template <class T, class... TArgs>
+template <std::derived_from<TPoolAllocator::TObjectBase> T, class... TArgs>
 std::unique_ptr<T> TPoolAllocator::New(TArgs&&... args)
 {
     struct TChunkTag

+ 10 - 10
yt/yt/core/misc/pool_allocator.h

@@ -42,16 +42,6 @@ public:
      */
     static void Free(void* ptr) noexcept;
 
-    //! Allocates a new object of type #T (typically derived from #TPoolAllocator::TObjectBase)
-    //! from a per-thread pool.
-    /*!
-     *  \note
-     *  The object's disposal via |operator delete| must take place within
-     *  the same thread the object was created.
-     */
-    template <class T, class... TArgs>
-    static std::unique_ptr<T> New(TArgs&&... args);
-
     //! A base for objects instantiated via #TPoolAllocator::New.
     class TObjectBase
     {
@@ -68,6 +58,16 @@ public:
         void operator delete[](void* ptr) noexcept;
     };
 
+    //! Allocates a new object of type #T (derived from #TPoolAllocator::TObjectBase)
+    //! from a per-thread pool.
+    /*!
+     *  \note
+     *  The object's disposal via |operator delete| must take place within
+     *  the same thread the object was created.
+     */
+    template <std::derived_from<TObjectBase> T, class... TArgs>
+    static std::unique_ptr<T> New(TArgs&&... args);
+
 private:
     const size_t BlockSize_;
     const size_t BlockAlignment_;