From f47e88adb36d0be24b6179c930729dc35b7e42ae Mon Sep 17 00:00:00 2001 From: i80287 Date: Sun, 10 Nov 2024 22:49:57 +0300 Subject: [PATCH] update RBTree and update modules compilation condition in the tests --- bstrees/RBTree.cppm | 14 +++++++------- bstrees/RBTreeTests.cpp | 6 +++++- tests/CMakeTestsUtils.cmake | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bstrees/RBTree.cppm b/bstrees/RBTree.cppm index a5668bc..f55811e 100644 --- a/bstrees/RBTree.cppm +++ b/bstrees/RBTree.cppm @@ -515,9 +515,11 @@ private: constexpr void AssertBeginInvariants() const noexcept { RBTREE_ASSERT_INVARIANT(GetBeginUnchecked() != nullptr); +#ifdef RBTREE_DEBUG const auto invariants_if_not_empty = Size() >= 1 && GetBeginUnchecked() != GetEndUnchecked(); const auto invariants_if_empty = Size() == 0 && GetBeginUnchecked() == GetEndUnchecked(); +#endif RBTREE_ASSERT_INVARIANT(invariants_if_not_empty ^ invariants_if_empty); RBTREE_ASSERT_INVARIANT(GetBeginUnchecked() == GetEndUnchecked() || GetBeginUnchecked()->Left() == nullptr); @@ -1187,7 +1189,6 @@ class RBTreeContainer : private RBTreeContainerImpl { using Base = RBTreeContainerImpl; protected: - using Base::Base; using size_type = std::size_t; using difference_type = std::ptrdiff_t; using const_iterator = Iterator; @@ -1208,7 +1209,7 @@ protected: static constexpr bool kIsNodeNoexceptDestructible = std::is_nothrow_destructible_v; - constexpr RBTreeContainer() = default; + constexpr RBTreeContainer() noexcept = default; constexpr RBTreeContainer(const RBTreeContainer &other) : Base(CloneTree(other)) {} constexpr RBTreeContainer &operator=(const RBTreeContainer &other) ATTRIBUTE_LIFETIME_BOUND { // NOLINTNEXTLINE(cppcoreguidelines-c-copy-assignment-signature) @@ -1647,7 +1648,6 @@ public: using node_type = typename Base::node_type; using allocator_type = typename Base::allocator_type; using Base::back; - using Base::Base; using Base::begin; using Base::cbegin; using Base::cend; @@ -1662,10 +1662,10 @@ public: using Base::rend; using Base::size; - RBTree(std::initializer_list list) : RBTree(list.begin(), list.end()) {} - - template - RBTree(Iter begin_iter, Iter end_iter) { + constexpr RBTree() noexcept = default; + constexpr RBTree(std::initializer_list list) : RBTree(list.begin(), list.end()) {} + template SentinelIter> + constexpr RBTree(Iter begin_iter, SentinelIter end_iter) { for (; begin_iter != end_iter; ++begin_iter) { insert(*begin_iter); // TODO: insert_hint } diff --git a/bstrees/RBTreeTests.cpp b/bstrees/RBTreeTests.cpp index d0e9a86..cf53cd9 100644 --- a/bstrees/RBTreeTests.cpp +++ b/bstrees/RBTreeTests.cpp @@ -151,13 +151,17 @@ void test_on_range(const Range1 &nums, const Range2 ¬_in_nums) { static_assert(std::is_same_v &&>); RBTree t2 = std::move(t1); compare(t2, checker); - t1 = std::move(t2); + RBTree &t1_ref = t1 = std::move(t2); + assert(std::addressof(t1_ref) == std::addressof(t1)); compare(t1, checker); t2.clear(); t2.swap(t1); compare(t2, checker); t2.swap(t1); compare(t1, checker); + RBTree &t2_ref = t2 = t1; + assert(std::addressof(t2_ref) == std::addressof(t2)); + compare(t2, checker); }; RBTree t; diff --git a/tests/CMakeTestsUtils.cmake b/tests/CMakeTestsUtils.cmake index 7a5d522..eed5979 100644 --- a/tests/CMakeTestsUtils.cmake +++ b/tests/CMakeTestsUtils.cmake @@ -495,10 +495,10 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 14.0.0) list(APPEND COMPILER_SUPPORTED_C_VERSIONS 23) - set(COMPILER_SUPPORTS_MODULES True) endif() if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.0.0) list(APPEND COMPILER_SUPPORTED_CXX_VERSIONS 26) + set(COMPILER_SUPPORTS_MODULES True) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") configure_msvc_or_clang_msvc_options()