Skip to content

Commit

Permalink
Update libcxx/multiset
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Oct 24, 2024
1 parent c3996b8 commit 9e26ad2
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/sources/libcxx/MultiSetTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ LIBCXX_TEST_BEGIN(insert_node_type_hint)
#include "multiset/insert_node_type_hint.pass.cpp"
LIBCXX_TEST_END

#if TEST_STD_VER >= 23
LIBCXX_TEST_BEGIN(insert_range)
#include "multiset/insert_range.pass.cpp"
LIBCXX_TEST_END
#endif

LIBCXX_TEST_BEGIN(insert_rv)
#include "multiset/insert_rv.pass.cpp"
LIBCXX_TEST_END
Expand Down Expand Up @@ -208,6 +214,12 @@ LIBCXX_TEST_BEGIN(cons_dtor_noexcept)
#include "multiset/multiset.cons/dtor_noexcept.pass.cpp"
LIBCXX_TEST_END

#if TEST_STD_VER >= 23
LIBCXX_TEST_BEGIN(cons_from_range)
#include "multiset/multiset.cons/from_range.pass.cpp"
LIBCXX_TEST_END
#endif

LIBCXX_TEST_BEGIN(cons_initializer_list)
#include "multiset/multiset.cons/initializer_list.pass.cpp"
LIBCXX_TEST_END
Expand Down
35 changes: 35 additions & 0 deletions test/sources/libcxx/multiset/insert_range.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Modified for https://github.com/morzhovets/momo project.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// Some fields in the test case variables are deliberately not explicitly initialized, this silences a warning on GCC.
// ADDITIONAL_COMPILE_FLAGS(gcc-style-warnings): -Wno-missing-field-initializers

// <set>

// template<container-compatible-range<value_type> R>
// void insert_range(R&& rg); // C++23

int main(int, char**) {
for_all_iterators_and_allocators<int, const int*>([]<class Iter, class Sent, class Alloc>() {
test_map_set_insert_range<std::multiset<int, test_less<int>, Alloc>, int, Iter, Sent>(/*allow_duplicates=*/true);
});

static_assert(test_set_constraints_insert_range<std::multiset, int, double>());

test_set_insert_range_move_only<std::multiset>();

test_set_insert_range_exception_safety_throwing_copy<std::multiset>();
test_assoc_set_insert_range_exception_safety_throwing_allocator<std::multiset, int>();

return 0;
}
38 changes: 38 additions & 0 deletions test/sources/libcxx/multiset/multiset.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
// template<class Key, class Allocator>
// multiset(initializer_list<Key>, Allocator)
// -> multiset<Key, less<Key>, Allocator>;
//
// template<ranges::input_range R, class Compare = less<ranges::range_value_t<R>>,
// class Allocator = allocator<ranges::range_value_t<R>>>
// multiset(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
// -> multiset<ranges::range_value_t<R>, Compare, Allocator>;
//
// template<ranges::input_range R, class Allocator>
// multiset(from_range_t, R&&, Allocator)
// -> multiset<ranges::range_value_t<R>, less<ranges::range_value_t<R>>, Allocator>;

struct NotAnAllocator {
friend bool operator<(NotAnAllocator, NotAnAllocator) { return false; }
Expand Down Expand Up @@ -189,6 +198,35 @@ int main(int, char **) {
}
#endif

#if TEST_STD_VER >= 23
{
using Range = std::array<int, 0>;
using Comp = std::greater<int>;
using DefaultComp = std::less<int>;
using Alloc = test_allocator<int>;

{ // (from_range, range)
momo::stdish::multiset c(std::from_range, Range());
static_assert(std::is_same_v<decltype(c), momo::stdish::multiset<int>>);
}

{ // (from_range, range, comp)
momo::stdish::multiset c(std::from_range, Range(), Comp());
static_assert(std::is_same_v<decltype(c), momo::stdish::multiset<int, Comp>>);
}

{ // (from_range, range, comp, alloc)
momo::stdish::multiset c(std::from_range, Range(), Comp(), Alloc());
static_assert(std::is_same_v<decltype(c), momo::stdish::multiset<int, Comp, Alloc>>);
}

{ // (from_range, range, alloc)
momo::stdish::multiset c(std::from_range, Range(), Alloc());
static_assert(std::is_same_v<decltype(c), momo::stdish::multiset<int, DefaultComp, Alloc>>);
}
}
#endif

//#if MOMO_VERSION_MAJOR > 3
#if !(defined(TEST_MSVC) && _MSC_VER < 1930) && !(defined(TEST_GCC) && __GNUC__ < 11)
AssociativeContainerDeductionGuidesSfinaeAway<std::multiset, std::multiset<int>>();
Expand Down
41 changes: 41 additions & 0 deletions test/sources/libcxx/multiset/multiset.cons/from_range.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Modified for https://github.com/morzhovets/momo project.
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20

// template<container-compatible-range<value_type> R>
// multiset(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
//
// template<container-compatible-range<value_type> R>
// multiset(from_range_t, R&& rg, const Allocator& a))
// : multiset(from_range, std::forward<R>(rg), Compare(), a) { } // C++23

void test_duplicates() {
std::array input = {1, 2, 3, 3, 3, 4, 2, 1, 2};
auto c = std::multiset<int>(std::from_range, input);
assert(std::ranges::is_permutation(input, c));
}

int main(int, char**) {
for_all_iterators_and_allocators<int>([]<class Iter, class Sent, class Alloc>() {
test_associative_set<std::multiset, int, Iter, Sent, test_less<int>, Alloc>();
});
test_associative_set_move_only<std::multiset>();
test_duplicates();

static_assert(test_set_constraints<std::multiset, int, double>());

test_set_exception_safety_throwing_copy<std::multiset>();
test_set_exception_safety_throwing_allocator<std::multiset, int>();

return 0;
}

0 comments on commit 9e26ad2

Please sign in to comment.