Skip to content

Commit

Permalink
update RBTree and update modules compilation condition in the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
i80287 committed Nov 10, 2024
1 parent 42281a6 commit f47e88a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
14 changes: 7 additions & 7 deletions bstrees/RBTree.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<KeyType, /*IsConstIterator = */ true, DerivedRBTree>;
Expand All @@ -1208,7 +1209,7 @@ protected:

static constexpr bool kIsNodeNoexceptDestructible = std::is_nothrow_destructible_v<NodeType>;

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)
Expand Down Expand Up @@ -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;
Expand All @@ -1662,10 +1662,10 @@ public:
using Base::rend;
using Base::size;

RBTree(std::initializer_list<KeyType> list) : RBTree(list.begin(), list.end()) {}

template <std::input_iterator Iter>
RBTree(Iter begin_iter, Iter end_iter) {
constexpr RBTree() noexcept = default;
constexpr RBTree(std::initializer_list<KeyType> list) : RBTree(list.begin(), list.end()) {}
template <std::input_iterator Iter, std::sentinel_for<Iter> SentinelIter>
constexpr RBTree(Iter begin_iter, SentinelIter end_iter) {
for (; begin_iter != end_iter; ++begin_iter) {
insert(*begin_iter); // TODO: insert_hint
}
Expand Down
6 changes: 5 additions & 1 deletion bstrees/RBTreeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,17 @@ void test_on_range(const Range1 &nums, const Range2 &not_in_nums) {
static_assert(std::is_same_v<decltype(std::move(t1)), RBTree<T> &&>);
RBTree<T> t2 = std::move(t1);
compare(t2, checker);
t1 = std::move(t2);
RBTree<T> &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<T> &t2_ref = t2 = t1;
assert(std::addressof(t2_ref) == std::addressof(t2));
compare(t2, checker);
};

RBTree<T> t;
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeTestsUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f47e88a

Please sign in to comment.