Skip to content

Commit

Permalink
Update libcxx/multimap
Browse files Browse the repository at this point in the history
  • Loading branch information
morzhovets committed Oct 25, 2024
1 parent 9b9a4cb commit 8c6faed
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/sources/libcxx/MultiMapTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ LIBCXX_TEST_BEGIN(cons_dtor_noexcept)
#include "multimap/multimap.cons/dtor_noexcept.pass.cpp"
LIBCXX_TEST_END

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

LIBCXX_TEST_BEGIN(cons_initializer_list)
#include "multimap/multimap.cons/initializer_list.pass.cpp"
LIBCXX_TEST_END
Expand Down Expand Up @@ -234,6 +240,12 @@ LIBCXX_TEST_BEGIN(modifiers_insert_node_type_hint)
#include "multimap/multimap.modifiers/insert_node_type_hint.pass.cpp"
LIBCXX_TEST_END

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

LIBCXX_TEST_BEGIN(modifiers_insert_rv)
#include "multimap/multimap.modifiers/insert_rv.pass.cpp"
LIBCXX_TEST_END
Expand Down
38 changes: 38 additions & 0 deletions test/sources/libcxx/multimap/multimap.cons/deduct.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
// template<class Key, class Allocator>
// multimap(initializer_list<Key>, Allocator)
// -> multimap<Key, less<Key>, Allocator>;
//
// template<ranges::input_range R, class Compare = less<range-key-type<R>>,
// class Allocator = allocator<range-to-alloc-type<R>>>
// multimap(from_range_t, R&&, Compare = Compare(), Allocator = Allocator())
// -> multimap<range-key-type<R>, range-mapped-type<R>, Compare, Allocator>; // C++23
//
// template<ranges::input_range R, class Allocator>
// multimap(from_range_t, R&&, Allocator)
// -> multimap<range-key-type<R>, range-mapped-type<R>, less<range-key-type<R>>, Allocator>; // C++23

using P = std::pair<int, long>;
using PC = std::pair<const int, long>;
Expand Down Expand Up @@ -158,6 +167,35 @@ int main(int, char**)
#endif
}

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

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

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

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

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

#if MOMO_VERSION_MAJOR > 3
#if !(defined(TEST_MSVC) && _MSC_VER < 1930) && !(defined(TEST_GCC) && __GNUC__ < 11)
AssociativeContainerDeductionGuidesSfinaeAway<std::multimap, std::multimap<int, long>>();
Expand Down
45 changes: 45 additions & 0 deletions test/sources/libcxx/multimap/multimap.cons/from_range.pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//===----------------------------------------------------------------------===//
//
// 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>
// multimap(from_range_t, R&& rg, const Compare& comp = Compare(), const Allocator& = Allocator()); // C++23
//
// template<container-compatible-range<value_type> R>
// multimap(from_range_t, R&& rg, const Allocator& a))
// : multimap(from_range, std::forward<R>(rg), Compare(), a) { } // C++23

void test_duplicates() {
using T = std::pair<const int, char>;
std::array input = {
T{1, 'a'}, T{2, 'a'}, T{3, 'a'}, T{3, 'b'}, T{3, 'c'}, T{2, 'b'}, T{4, 'a'}
};
auto c = std::multimap<int, char>(std::from_range, input);
assert(std::ranges::is_permutation(input, c));
}

int main(int, char**) {
using T = std::pair<const int, int>;
for_all_iterators_and_allocators<T>([]<class Iter, class Sent, class Alloc>() {
test_associative_map<std::multimap, int, int, Iter, Sent, test_less<int>, Alloc>();
});
test_associative_map_move_only<std::multimap>();
test_duplicates();

static_assert(test_map_constraints<std::multimap, int, int, double, double>());

test_map_exception_safety_throwing_copy<std::multimap>();
test_map_exception_safety_throwing_allocator<std::multimap, int, int>();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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

// <map>

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

int main(int, char**) {
// Note: we want to use a pair with non-const elements for input (an assignable type is a lot more convenient) but
// have to use the exact `value_type` of the map (that is, `pair<const K, V>`) for the allocator.
using Pair = std::pair<int, char>;
using ConstPair = std::pair<const int, char>;
for_all_iterators_and_allocators<ConstPair, const Pair*>([]<class Iter, class Sent, class Alloc>() {
test_map_set_insert_range<std::multimap<int, char, test_less<int>, Alloc>, Pair, Iter, Sent>(/*allow_duplicates=*/true);
});

static_assert(test_map_constraints_insert_range<std::multimap, int, int, char, double>());

test_map_insert_range_move_only<std::multimap>();

test_map_insert_range_exception_safety_throwing_copy<std::multimap>();
test_assoc_map_insert_range_exception_safety_throwing_allocator<std::multimap, int, int>();

return 0;
}

0 comments on commit 8c6faed

Please sign in to comment.