diff options
| author | arkady-e1ppa <[email protected]> | 2024-12-17 18:55:00 +0300 |
|---|---|---|
| committer | arkady-e1ppa <[email protected]> | 2024-12-17 19:15:57 +0300 |
| commit | 174f410da8f66e7525c017656f485eb45a978a09 (patch) | |
| tree | 847704b1c5cf78425dae037e6cac45005e70cb62 /library/cpp | |
| parent | 3474e0dbe58ae22cfd6d8784f476dbf816a1524d (diff) | |
Use AnyObject to remove type erasure logic from yt/yt/core
commit_hash:79b0a0b437e41879c3a7d4c079ab571bbaafd45f
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/yt/memory/type_erasure.h | 4 | ||||
| -rw-r--r-- | library/cpp/yt/memory/type_erasure_detail.h | 14 | ||||
| -rw-r--r-- | library/cpp/yt/memory/unittests/type_erasure_ut.cpp | 8 |
3 files changed, 19 insertions, 7 deletions
diff --git a/library/cpp/yt/memory/type_erasure.h b/library/cpp/yt/memory/type_erasure.h index 92c4eb34c54..4c4afaecb26 100644 --- a/library/cpp/yt/memory/type_erasure.h +++ b/library/cpp/yt/memory/type_erasure.h @@ -218,7 +218,7 @@ public: auto* mover = GetVTable().template GetFunctor<Mover<TStorage>>(); mover(std::move(other).GetStorage(), GetStorage()); - other.Holder_.Reset(); + other.Reset(); } } @@ -236,7 +236,7 @@ public: auto* mover = GetVTable().template GetFunctor<Mover<TStorage>>(); mover(std::move(other).GetStorage(), GetStorage()); - other.Holder_.Reset(); + other.Reset(); } return *this; diff --git a/library/cpp/yt/memory/type_erasure_detail.h b/library/cpp/yt/memory/type_erasure_detail.h index 5e158d3a814..3de22b8e0d0 100644 --- a/library/cpp/yt/memory/type_erasure_detail.h +++ b/library/cpp/yt/memory/type_erasure_detail.h @@ -369,11 +369,19 @@ private: //////////////////////////////////////////////////////////////////////////////// template <class T, class TStorage> +struct TIsVTable + : public std::false_type +{ }; + +template <CStorage TStorage, class... TCpos> +struct TIsVTable<TVTable<TStorage, TCpos...>, TStorage> + : public std::true_type +{ }; + +template <class T, class TStorage> concept CVTableFor = CStorage<TStorage> && - requires (const T& t) { - [] <class... TCpos> (TVTable<TStorage, TCpos...>) { } (t); - }; + TIsVTable<std::remove_cvref_t<T>, TStorage>::value; //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yt/memory/unittests/type_erasure_ut.cpp b/library/cpp/yt/memory/unittests/type_erasure_ut.cpp index e6e917d9756..5c91d654bfd 100644 --- a/library/cpp/yt/memory/unittests/type_erasure_ut.cpp +++ b/library/cpp/yt/memory/unittests/type_erasure_ut.cpp @@ -292,7 +292,10 @@ TEST(TAnyObjectTest, CvRefCorrectness) EXPECT_EQ(TestCpo(movedOut).Val, 11); } - EXPECT_EQ(cust.DtorCount, 5); + // NB(arkady-e1ppa): Moved out any should be + // actually empty thus moving out both moves object out + // and destroys the moved out object. + EXPECT_EQ(cust.DtorCount, 6); EXPECT_THROW(any.AnyCast<TCustomized2>(), NDetail::TBadAnyCast); } @@ -316,7 +319,8 @@ TEST(TAnyObjectTest, StaticVTableForAnyRef) EXPECT_EQ(TestCpo(movedOut).Val, 11); } EXPECT_EQ(cst.Value, 1111); - EXPECT_EQ(cst.DtorCount, 2); + // NB(arkady-e1ppa): See comment in previous test. + EXPECT_EQ(cst.DtorCount, 3); EXPECT_FALSE(any.IsValid()); } |
