From a29e3026b9c9b225ad2085e28085721dda3f53b2 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Fri, 14 Mar 2025 14:26:05 +0800 Subject: [PATCH 1/4] [libc++][test] Avoid narrowing operations in `pair`' constructors ... for test files for `flat_(multi)map` whenever feasible. Drive-by: Add `[[maybe_unused]]` to variables that are only used in `LIBCPP_ASSERT`. When testing MSVC STL, MSVC warns about such narrowing in `pair`'s constructors, even though the narrowing happens within direct-non-list-initialization. --- .../flat.map.cons/copy_assign.pass.cpp | 8 ++- .../flat.map/flat.map.cons/deduct.pass.cpp | 44 ++++++++++++--- .../flat.map.cons/deduct_pmr.pass.cpp | 12 +++- .../flat.map.cons/initializer_list.pass.cpp | 51 ++++++++++++++--- .../flat.map/flat.map.cons/iter_iter.pass.cpp | 15 ++++- .../flat.map.cons/move_assign.pass.cpp | 15 +++-- .../flat.map/flat.map.cons/pmr.pass.cpp | 30 ++++++++-- .../flat.map/flat.map.cons/range.pass.cpp | 15 ++++- .../flat.map.cons/sorted_container.pass.cpp | 25 +++++++-- .../sorted_initializer_list.pass.cpp | 19 +++++-- .../flat.map.cons/sorted_iter_iter.pass.cpp | 13 ++++- .../erase_if_exceptions.pass.cpp | 3 +- .../flat.map.modifiers/erase_key.pass.cpp | 2 +- .../flat.multimap.cons/containers.pass.cpp | 33 ++++++++++- .../flat.multimap.cons/copy_assign.pass.cpp | 8 ++- .../flat.multimap.cons/deduct.pass.cpp | 54 +++++++++++++++--- .../flat.multimap.cons/deduct_pmr.pass.cpp | 18 +++++- .../initializer_list.pass.cpp | 56 ++++++++++++++++--- .../flat.multimap.cons/iter_iter.pass.cpp | 24 +++++++- .../flat.multimap.cons/move_assign.pass.cpp | 19 +++++-- .../flat.multimap.cons/pmr.pass.cpp | 48 ++++++++++++++-- .../flat.multimap.cons/range.pass.cpp | 24 +++++++- .../sorted_container.pass.cpp | 20 +++++-- .../sorted_initializer_list.pass.cpp | 19 +++++-- .../sorted_iter_iter.pass.cpp | 13 +++-- .../erase_if_exceptions.pass.cpp | 3 +- .../erase_key.pass.cpp | 2 +- 27 files changed, 488 insertions(+), 105 deletions(-) diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp index 4f9797d5bf810..cc80de8950738 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp @@ -29,7 +29,9 @@ int main(int, char**) { std::vector> vs({2, 2, 1}, test_allocator(7)); using M = std::flat_map; auto mo = M(ks, vs, C(5)); - auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator(2)); + auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, + C(3), + test_allocator(2)); m = mo; assert(m.key_comp() == C(5)); @@ -54,7 +56,9 @@ int main(int, char**) { auto vs = Vs({2, 2, 1}, other_allocator(7)); using M = std::flat_map; auto mo = M(Ks(ks, other_allocator(6)), Vs(vs, other_allocator(7)), C(5)); - auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator(2)); + auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, + C(3), + other_allocator(2)); m = mo; assert(m.key_comp() == C(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp index 009392feb3862..3ca7aa1363856 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp @@ -31,19 +31,19 @@ using PC = std::pair; void test_copy() { { - std::flat_map source = {{1, 2}, {2, 3}}; + std::flat_map source = {{1, static_cast(2)}, {2, static_cast(3)}}; std::flat_map s(source); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_map> source = {{1, 2}, {2, 3}}; + std::flat_map> source = {{1, static_cast(2)}, {2, static_cast(3)}}; std::flat_map s{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_map> source = {{1, 2}, {2, 3}}; + std::flat_map> source = {{1, static_cast(2)}, {2, static_cast(3)}}; std::flat_map s(source, std::allocator()); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); @@ -55,7 +55,11 @@ void test_containers() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({1, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 2, 5, 4}, test_allocator(0, 43)); - const std::pair expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {3, static_cast(5)}, + {INT_MAX, static_cast(4)}}; { std::flat_map s(ks, vs); @@ -95,7 +99,11 @@ void test_containers_compare() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator(0, 42)); std::deque> sorted_vs({4, 5, 2, 1}, test_allocator(0, 43)); - const std::pair expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}}; + const std::pair expected[] = { + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}, + {2, static_cast(2)}, + {1, static_cast(1)}}; { std::flat_map s(ks, vs, std::greater()); @@ -278,8 +286,17 @@ void test_initializer_list_compare() { } void test_from_range() { - std::list> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}}; - const std::pair expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}}; + std::list> r = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {1, static_cast(1)}, + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {3, static_cast(5)}, + {INT_MAX, static_cast(4)}}; { std::flat_map s(std::from_range, r); ASSERT_SAME_TYPE(decltype(s), std::flat_map>); @@ -301,8 +318,17 @@ void test_from_range() { } void test_from_range_compare() { - std::list> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}}; - const std::pair expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}}; + std::list> r = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {1, static_cast(1)}, + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}}; + const std::pair expected[] = { + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}, + {2, static_cast(2)}, + {1, static_cast(1)}}; { std::flat_map s(std::from_range, r, std::greater()); ASSERT_SAME_TYPE(decltype(s), std::flat_map>); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp index 11c18ac13c76a..e62b9049859aa 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp @@ -35,7 +35,11 @@ void test_containers() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({1, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 2, 5, 4}, test_allocator(0, 43)); - const std::pair expected[] = {{1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {3, static_cast(5)}, + {INT_MAX, static_cast(4)}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; @@ -69,7 +73,11 @@ void test_containers_compare() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator(0, 42)); std::deque> sorted_vs({4, 5, 2, 1}, test_allocator(0, 43)); - const std::pair expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}}; + const std::pair expected[] = { + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}, + {2, static_cast(2)}, + {1, static_cast(1)}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp index 7a22746845d00..5fa8b040a31e8 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp @@ -82,11 +82,18 @@ int main(int, char**) { !std::is_constructible_v>, std::allocator>); } - std::pair expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}}; + std::pair expected[] = { + {1, static_cast(1)}, {2, static_cast(2)}, {3, static_cast(3)}, {5, static_cast(2)}}; { // flat_map(initializer_list); using M = std::flat_map; - std::initializer_list> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + std::initializer_list> il = { + {5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; M m(il); assert(std::equal(m.begin(), m.end(), expected, expected + 4)); } @@ -94,13 +101,23 @@ int main(int, char**) { // flat_map(initializer_list); // explicit(false) using M = std::flat_map; - M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + M m = {{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; assert(std::equal(m.begin(), m.end(), expected, expected + 4)); } { // flat_map(initializer_list); using M = std::flat_map, std::deque>>; - M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + M m = {{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4)); } { @@ -127,12 +144,25 @@ int main(int, char**) { // flat_map(initializer_list, const key_compare&); using C = test_less; using M = std::flat_map; - auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)); + auto m = + M({{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + C(10)); assert(std::equal(m.begin(), m.end(), expected, expected + 4)); assert(m.key_comp() == C(10)); // explicit(false) - M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)}; + M m2 = {{{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + C(10)}; assert(m2 == m); assert(m2.key_comp() == C(10)); } @@ -140,7 +170,14 @@ int main(int, char**) { // flat_map(initializer_list, const key_compare&); // Sorting uses the comparator that was passed in using M = std::flat_map, std::deque>>; - auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater()); + auto m = + M({{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + std::greater()); assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4)); assert(m.key_comp()(2, 1) == true); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp index 7c0c487969943..6fb6eef67bb03 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp @@ -57,9 +57,18 @@ int main(int, char**) { static_assert(!std::is_constructible_v); } - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {2, 4}, {3, 6}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; { // flat_map(InputIterator , InputIterator) // cpp17_input_iterator diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp index a94c442c695dd..ad305ae41cdf2 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp @@ -32,10 +32,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_map, std::vector>; - M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7)); + M mo = M({{1, static_cast(1)}, {2, static_cast(3)}, {3, static_cast(2)}}, C(5), A1(7)); M m = M({}, C(3), A1(7)); m = std::move(mo); - assert((m == M{{1, 1}, {2, 3}, {3, 2}})); + assert((m == M{{1, static_cast(1)}, {2, static_cast(3)}, {3, static_cast(2)}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); @@ -47,10 +47,15 @@ int main(int, char**) { using A1 = other_allocator; using A2 = other_allocator; using M = std::flat_map, std::deque>; - M mo = M({{4, 5}, {5, 4}}, C(5), A1(7)); - M m = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7)); + M mo = M({{4, static_cast(5)}, {5, static_cast(4)}}, C(5), A1(7)); + M m = M({{1, static_cast(1)}, // + {2, static_cast(2)}, + {3, static_cast(3)}, + {4, static_cast(4)}}, + C(3), + A1(7)); m = std::move(mo); - assert((m == M{{4, 5}, {5, 4}})); + assert((m == M{{4, static_cast(5)}, {5, static_cast(4)}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp index 154af11bb9b4d..d1c86bb077ed5 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp @@ -166,9 +166,18 @@ int main(int, char**) { } { // flat_map(InputIterator first, InputIterator last, const Allocator& a); - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {2, 4}, {3, 6}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; { // cpp17 iterator using M = std::flat_map, std::pmr::vector, std::pmr::vector>; @@ -242,9 +251,18 @@ int main(int, char**) { } { // flat_map(from_range_t, R&&, const Alloc&); - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {2, 4}, {3, 6}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; { // input_range using M = std::flat_map, std::pmr::vector, std::pmr::vector>; diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp index 282cc71f31994..c34109a1801ba 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp @@ -117,9 +117,18 @@ int main(int, char**) { static_assert(!std::is_constructible_v&, const C&, const A1&>); } - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {2, 4}, {3, 6}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; { // flat_map(from_range_t, R&&) // input_range && !common diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp index 3c8868f2ff424..bde86ea2ddbe4 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp @@ -66,11 +66,17 @@ int main(int, char**) { auto vs2 = vs; auto m = M(std::sorted_unique, ks, vs); - assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); m = M(std::sorted_unique, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); // explicit(false) M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)}; @@ -85,11 +91,17 @@ int main(int, char**) { Ks ks = {10, 4, 2, 1}; Vs vs = {1, 2, 3, 4}; auto m = M(std::sorted_unique, ks, vs); - assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); m = M(std::sorted_unique, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); } { // flat_map(sorted_unique_t, key_container_type , mapped_container_type) @@ -113,7 +125,10 @@ int main(int, char**) { std::vector vs = {4, 3, 2, 1}; auto m = M(std::sorted_unique, ks, vs, C(4)); - assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); assert(m.key_comp() == C(4)); // explicit(false) diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp index 26452472ba201..343cc57ad12bf 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp @@ -31,7 +31,11 @@ #include "../../../test_compare.h" template -std::initializer_list> il = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; +std::initializer_list> il = { + {static_cast(1), static_cast(1)}, + {static_cast(2), static_cast(2)}, + {static_cast(4), static_cast(4)}, + {static_cast(5), static_cast(5)}}; const auto il1 = il; const auto il2 = il; @@ -140,7 +144,8 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::vector, std::deque>; auto m = M(std::sorted_unique, il2, A1(5)); - auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}; + auto expected = M{ + {1, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -158,7 +163,10 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::deque>; auto m = M(std::sorted_unique, il2, C(3), A1(5)); - assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}})); + assert((m == M{{1, static_cast(1)}, + {2, static_cast(2)}, + {4, static_cast(4)}, + {5, static_cast(5)}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -170,7 +178,10 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::deque, std::vector>; M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor - assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}})); + assert((m == M{{static_cast(1), 1}, + {static_cast(2), 2}, + {static_cast(4), 4}, + {static_cast(5), 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp index 8eb7547e917cc..3b27e684ec91b 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp @@ -128,7 +128,8 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; auto m = M(std::sorted_unique, ar, ar + 4, A1(5)); - auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}; + auto expected = M{ + {1, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -148,7 +149,10 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; auto m = M(std::sorted_unique, ar, ar + 4, C(3), A1(5)); - assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}})); + assert((m == M{{1, static_cast(1)}, + {2, static_cast(2)}, + {4, static_cast(4)}, + {5, static_cast(5)}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -162,7 +166,10 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; M m = {std::sorted_unique, ar, ar + 4, {}, A1(5)}; // implicit ctor - assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}})); + assert((m == M{{static_cast(1), 1}, + {static_cast(2), 2}, + {static_cast(4), 4}, + {static_cast(5), 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if_exceptions.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if_exceptions.pass.cpp index 48fdec42db3fc..c0e31dc38426c 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if_exceptions.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.erasure/erase_if_exceptions.pass.cpp @@ -66,7 +66,8 @@ struct ErasurePredicate { }; int main(int, char**) { - const std::pair expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}}; + [[maybe_unused]] const std::pair expected[] = { + {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}}; { using M = std::flat_map; for (int first_throw = 1; first_throw < 99; ++first_throw) { diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp index ef57b1cb5512d..d019c5eeaa1b9 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.modifiers/erase_key.pass.cpp @@ -32,7 +32,7 @@ void test() { auto make = [](std::initializer_list il) { M m; for (int i : il) { - m.emplace(i, i); + m.emplace(i, static_cast(i)); } return m; }; diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp index 17ee3c3864b1b..f78f984dc6992 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp @@ -71,7 +71,16 @@ int main(int, char**) { std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto m = M(ks, vs); - std::pair expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; assert(std::ranges::equal(m, expected)); // explicit(false) @@ -123,7 +132,16 @@ int main(int, char**) { std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto m = M(ks, vs, C(4)); - std::pair expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(4)); @@ -169,7 +187,16 @@ int main(int, char**) { std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; auto m = M(ks, vs, C(4), A(5)); - std::pair expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(4)); assert(m.keys().get_allocator() == A(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp index 3dd7ebdd38871..8a66a74690fe4 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp @@ -29,7 +29,9 @@ int main(int, char**) { std::vector> vs({1, 2, 3, 4, 5}, test_allocator(7)); using M = std::flat_multimap; auto mo = M(ks, vs, C(5)); - auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator(2)); + auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, + C(3), + test_allocator(2)); m = mo; assert(m.key_comp() == C(5)); @@ -54,7 +56,9 @@ int main(int, char**) { auto vs = Vs({2, 1, 3, 2, 1}, other_allocator(7)); using M = std::flat_multimap; auto mo = M(Ks(ks, other_allocator(6)), Vs(vs, other_allocator(7)), C(5)); - auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator(2)); + auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, + C(3), + other_allocator(2)); m = mo; assert(m.key_comp() == C(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp index a718d9cfad5b7..152786dc3b337 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp @@ -31,19 +31,21 @@ using PC = std::pair; void test_copy() { { - std::flat_multimap source = {{1, 2}, {1, 3}}; + std::flat_multimap source = {{1, static_cast(2)}, {1, static_cast(3)}}; std::flat_multimap s(source); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_multimap> source = {{1, 2}, {1, 3}}; + std::flat_multimap> source = { + {1, static_cast(2)}, {1, static_cast(3)}}; std::flat_multimap s{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_multimap> source = {{1, 2}, {1, 3}}; + std::flat_multimap> source = { + {1, static_cast(2)}, {1, static_cast(3)}}; std::flat_multimap s(source, std::allocator()); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); @@ -55,7 +57,14 @@ void test_containers() { std::deque> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator(0, 43)); std::deque> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator(0, 43)); - const std::pair expected[] = {{1, 1}, {1, 3}, {2, 2}, {2, 4}, {2, 5}, {3, 4}, {INT_MAX, 3}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(3)}, + {2, static_cast(2)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(4)}, + {INT_MAX, static_cast(3)}}; { std::flat_multimap s(ks, vs); @@ -95,7 +104,14 @@ void test_containers_compare() { std::deque> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator(0, 42)); std::deque> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator(0, 43)); - const std::pair expected[] = {{INT_MAX, 3}, {3, 4}, {2, 2}, {2, 4}, {2, 5}, {1, 1}, {1, 3}}; + const std::pair expected[] = { + {INT_MAX, static_cast(3)}, + {3, static_cast(4)}, + {2, static_cast(2)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {1, static_cast(1)}, + {1, static_cast(3)}}; { std::flat_multimap s(ks, vs, std::greater()); @@ -280,8 +296,18 @@ void test_initializer_list_compare() { } void test_from_range() { - std::list> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}}; - const std::pair expected[] = {{1, 1}, {1, 1}, {2, 2}, {3, 5}, {INT_MAX, 4}}; + std::list> r = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {1, static_cast(1)}, + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(1)}, + {2, static_cast(2)}, + {3, static_cast(5)}, + {INT_MAX, static_cast(4)}}; { std::flat_multimap s(std::from_range, r); ASSERT_SAME_TYPE(decltype(s), std::flat_multimap>); @@ -303,8 +329,18 @@ void test_from_range() { } void test_from_range_compare() { - std::list> r = {{1, 1}, {2, 2}, {1, 1}, {INT_MAX, 4}, {3, 5}}; - const std::pair expected[] = {{INT_MAX, 4}, {3, 5}, {2, 2}, {1, 1}, {1, 1}}; + std::list> r = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {1, static_cast(1)}, + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}}; + const std::pair expected[] = { + {INT_MAX, static_cast(4)}, + {3, static_cast(5)}, + {2, static_cast(2)}, + {1, static_cast(1)}, + {1, static_cast(1)}}; { std::flat_multimap s(std::from_range, r, std::greater()); ASSERT_SAME_TYPE(decltype(s), std::flat_multimap>); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp index 1955a8806631b..c775f937a3890 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp @@ -35,7 +35,14 @@ void test_containers() { std::deque> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator(0, 43)); std::deque> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator(0, 43)); - const std::pair expected[] = {{1, 1}, {1, 3}, {2, 2}, {2, 4}, {2, 5}, {3, 4}, {INT_MAX, 3}}; + const std::pair expected[] = { + {1, static_cast(1)}, + {1, static_cast(3)}, + {2, static_cast(2)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(4)}, + {INT_MAX, static_cast(3)}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; @@ -69,7 +76,14 @@ void test_containers_compare() { std::deque> vs({1, 2, 3, 4, 5, 3, 4}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator(0, 42)); std::deque> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator(0, 43)); - const std::pair expected[] = {{INT_MAX, 3}, {3, 4}, {2, 2}, {2, 4}, {2, 5}, {1, 1}, {1, 3}}; + const std::pair expected[] = { + {INT_MAX, static_cast(3)}, + {3, static_cast(4)}, + {2, static_cast(2)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {1, static_cast(1)}, + {1, static_cast(3)}}; { std::pmr::monotonic_buffer_resource mr; diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp index 8e89192ec0ea1..f81a9ebdfc87f 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp @@ -83,11 +83,23 @@ int main(int, char**) { !std::is_constructible_v>, std::allocator>); } - std::pair expected[] = {{1, 1}, {2, 2}, {2, 2}, {3, 3}, {3, 3}, {5, 2}}; + std::pair expected[] = { + {1, static_cast(1)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {3, static_cast(3)}, + {5, static_cast(2)}}; { // flat_multimap(initializer_list); using M = std::flat_multimap; - std::initializer_list> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + std::initializer_list> il = { + {5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; M m(il); assert(std::ranges::equal(m, expected)); } @@ -95,13 +107,23 @@ int main(int, char**) { // flat_multimap(initializer_list); // explicit(false) using M = std::flat_multimap; - M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + M m = {{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; assert(std::ranges::equal(m, expected)); } { // flat_multimap(initializer_list); using M = std::flat_multimap, std::deque>>; - M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}; + M m = {{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}; assert(std::equal(m.rbegin(), m.rend(), expected, expected + 6)); } { @@ -129,12 +151,25 @@ int main(int, char**) { // flat_multimap(initializer_list, const key_compare&); using C = test_less; using M = std::flat_multimap; - auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)); + auto m = + M({{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + C(10)); assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(10)); // explicit(false) - M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)}; + M m2 = {{{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + C(10)}; assert(m2 == m); assert(m2.key_comp() == C(10)); } @@ -142,7 +177,14 @@ int main(int, char**) { // flat_multimap(initializer_list, const key_compare&); // Sorting uses the comparator that was passed in using M = std::flat_multimap, std::deque>>; - auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater()); + auto m = + M({{5, static_cast(2)}, + {2, static_cast(2)}, + {2, static_cast(2)}, + {3, static_cast(3)}, + {1, static_cast(1)}, + {3, static_cast(3)}}, + std::greater()); assert(std::equal(m.rbegin(), m.rend(), expected, expected + 6)); assert(m.key_comp()(2, 1) == true); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp index c9c5e6c99d1c8..25c0cf04aaed6 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp @@ -57,9 +57,27 @@ int main(int, char**) { static_assert(!std::is_constructible_v); } - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; { // flat_multimap(InputIterator , InputIterator) // cpp17_input_iterator diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp index 38200d008c78a..b033e5f3948cc 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp @@ -32,7 +32,7 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_multimap, std::vector>; - M mo = M({{1, 1}, {1, 3}, {3, 2}}, C(5), A1(7)); + M mo = M({{1, static_cast(1)}, {1, static_cast(3)}, {3, static_cast(2)}}, C(5), A1(7)); M m = M({}, C(3), A1(7)); m = std::move(mo); assert((m == M{{1, 1}, {1, 3}, {3, 2}})); @@ -47,8 +47,13 @@ int main(int, char**) { using A1 = other_allocator; using A2 = other_allocator; using M = std::flat_multimap, std::deque>; - M mo = M({{4, 5}, {4, 4}}, C(5), A1(7)); - M m = M({{1, 1}, {1, 2}, {1, 3}, {4, 4}}, C(3), A1(7)); + M mo = M({{4, static_cast(5)}, {4, static_cast(4)}}, C(5), A1(7)); + M m = M({{1, static_cast(1)}, // + {1, static_cast(2)}, + {1, static_cast(3)}, + {4, static_cast(4)}}, + C(3), + A1(7)); m = std::move(mo); assert((m == M{{4, 5}, {4, 4}})); assert(m.key_comp() == C(5)); @@ -60,8 +65,12 @@ int main(int, char**) { { using A = min_allocator; using M = std::flat_multimap, std::vector, std::vector>; - M mo = M({{5, 1}, {5, 2}, {3, 3}}, A()); - M m = M({{4, 4}, {4, 3}, {4, 2}, {1, 1}}, A()); + M mo = M({{5, static_cast(1)}, {5, static_cast(2)}, {3, static_cast(3)}}, A()); + M m = M({{4, static_cast(4)}, // + {4, static_cast(3)}, + {4, static_cast(2)}, + {1, static_cast(1)}}, + A()); m = std::move(mo); assert((m == M{{5, 1}, {5, 2}, {3, 3}})); auto [ks, vs] = std::move(m).extract(); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp index 8b518f6afbda9..c6c8a10cafc5a 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp @@ -166,9 +166,27 @@ int main(int, char**) { } { // flat_multimap(InputIterator first, InputIterator last, const Allocator& a); - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; { // cpp17 iterator using M = std::flat_multimap, std::pmr::vector, std::pmr::vector>; @@ -242,9 +260,27 @@ int main(int, char**) { } { // flat_multimap(from_range_t, R&&, const Alloc&); - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; { // input_range using M = std::flat_multimap, std::pmr::vector, std::pmr::vector>; diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp index de750e2506341..d5e380dbfcd4d 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp @@ -117,9 +117,27 @@ int main(int, char**) { static_assert(!std::is_constructible_v&, const C&, const A1&>); } - using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; - P expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; + using P = std::pair; + P ar[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {3, static_cast(6)}, + {2, static_cast(7)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; + P expected[] = { + {1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(3)}, + {2, static_cast(4)}, + {2, static_cast(5)}, + {2, static_cast(7)}, + {3, static_cast(6)}, + {3, static_cast(8)}, + {3, static_cast(9)}}; { // flat_multimap(from_range_t, R&&) // input_range && !common diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp index 16579f0deed5d..4534d5d0d249d 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp @@ -66,11 +66,17 @@ int main(int, char**) { auto vs2 = vs; auto m = M(std::sorted_equivalent, ks, vs); - assert((m == M{{1, 4}, {4, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {4, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); m = M(std::sorted_equivalent, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, 4}, {4, 3}, {4, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {4, static_cast(3)}, + {4, static_cast(2)}, + {10, static_cast(1)}})); // explicit(false) M m2 = {std::sorted_equivalent, std::move(ks2), std::move(vs2)}; @@ -85,7 +91,10 @@ int main(int, char**) { Ks ks = {10, 1, 1, 1}; Vs vs = {1, 2, 3, 4}; auto m = M(std::sorted_equivalent, ks, vs); - assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}})); + assert((m == M{{1, static_cast(2)}, + {1, static_cast(3)}, + {1, static_cast(4)}, + {10, static_cast(1)}})); m = M(std::sorted_equivalent, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from @@ -113,7 +122,10 @@ int main(int, char**) { std::vector vs = {4, 3, 2, 1}; auto m = M(std::sorted_equivalent, ks, vs, C(4)); - assert((m == M{{1, 4}, {2, 3}, {10, 2}, {10, 1}})); + assert((m == M{{1, static_cast(4)}, + {2, static_cast(3)}, + {10, static_cast(2)}, + {10, static_cast(1)}})); assert(m.key_comp() == C(4)); // explicit(false) diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp index b34313bb3d404..c33a259acd5e5 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp @@ -31,7 +31,11 @@ #include "../../../test_compare.h" template -std::initializer_list> il = {{1, 1}, {4, 2}, {4, 4}, {5, 5}}; +std::initializer_list> il = { + {static_cast(1), static_cast(1)}, + {static_cast(4), static_cast(2)}, + {static_cast(4), static_cast(4)}, + {static_cast(5), static_cast(5)}}; const auto il1 = il; const auto il2 = il; @@ -144,7 +148,8 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::vector, std::deque>; auto m = M(std::sorted_equivalent, il2, A1(5)); - auto expected = M{{1, 1}, {4, 2}, {4, 4}, {5, 5}}; + auto expected = M{ + {1, static_cast(1)}, {4, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -162,7 +167,10 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::deque>; auto m = M(std::sorted_equivalent, il2, C(3), A1(5)); - assert((m == M{{1, 1}, {4, 2}, {4, 4}, {5, 5}})); + assert((m == M{{1, static_cast(1)}, + {4, static_cast(2)}, + {4, static_cast(4)}, + {5, static_cast(5)}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -174,7 +182,10 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::deque, std::vector>; M m = {std::sorted_equivalent, il3, {}, A1(5)}; // implicit ctor - assert((m == M{{1, 1}, {4, 2}, {4, 4}, {5, 5}})); + assert((m == M{{static_cast(1), 1}, + {static_cast(4), 2}, + {static_cast(4), 4}, + {static_cast(5), 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp index 45c4b3dc675a5..bd96fa91bc65f 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp @@ -130,7 +130,8 @@ int main(int, char**) { using P = std::pair; P ar[] = {{2, 1}, {2, 2}, {4, 4}, {5, 5}}; auto m = M(std::sorted_equivalent, ar, ar + 4, A1(5)); - auto expected = M{{2, 1}, {2, 2}, {4, 4}, {5, 5}}; + auto expected = M{ + {2, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -150,7 +151,10 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {1, 2}, {1, 4}, {1, 5}}; auto m = M(std::sorted_equivalent, ar, ar + 4, C(3), A1(5)); - assert((m == M{{1, 1}, {1, 2}, {1, 4}, {1, 5}})); + assert((m == M{{1, static_cast(1)}, + {1, static_cast(2)}, + {1, static_cast(4)}, + {1, static_cast(5)}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -162,8 +166,9 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::deque, std::vector>; using P = std::pair; - P ar[] = {{1, 1}, {1, 2}, {1, 4}, {1, 5}}; - M m = {std::sorted_equivalent, ar, ar + 4, {}, A1(5)}; // implicit ctor + P ar[] = { + {static_cast(1), 1}, {static_cast(1), 2}, {static_cast(1), 4}, {static_cast(1), 5}}; + M m = {std::sorted_equivalent, ar, ar + 4, {}, A1(5)}; // implicit ctor assert((m == M{{1, 1}, {1, 2}, {1, 4}, {1, 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.erasure/erase_if_exceptions.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.erasure/erase_if_exceptions.pass.cpp index 13b57202f7862..95f7e11626a4e 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.erasure/erase_if_exceptions.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.erasure/erase_if_exceptions.pass.cpp @@ -68,7 +68,8 @@ struct ErasurePredicate { }; int main(int, char**) { - const std::pair expected[] = {{1, 1}, {2, 2}, {3, 3}, {3, 3}, {5, 5}, {6, 6}, {7, 7}, {8, 8}}; + [[maybe_unused]] const std::pair expected[] = { + {1, 1}, {2, 2}, {3, 3}, {3, 3}, {5, 5}, {6, 6}, {7, 7}, {8, 8}}; { using M = std::flat_multimap; for (int first_throw = 1; first_throw < 99; ++first_throw) { diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/erase_key.pass.cpp index 7944996fba1a0..b9624d45a8041 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/erase_key.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.modifiers/erase_key.pass.cpp @@ -34,7 +34,7 @@ void test() { auto make = [](std::initializer_list il) { M m; for (int i : il) { - m.emplace(i, i); + m.emplace(i, static_cast(i)); } return m; }; From 69fb59a251d09c56cb61bc76c1f12dda341f21fd Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 26 Mar 2025 11:50:12 +0800 Subject: [PATCH 2/4] Remove awkward `static_cast(N)` and use character literals --- .../flat.map.cons/copy_assign.pass.cpp | 12 ++--- .../flat.map.cons/move_assign.pass.cpp | 15 ++---- .../flat.map.cons/sorted_container.pass.cpp | 31 ++++-------- .../flat.multimap.cons/containers.pass.cpp | 47 +++++-------------- .../flat.multimap.cons/copy_assign.pass.cpp | 12 ++--- .../flat.multimap.cons/move_assign.pass.cpp | 19 ++------ .../sorted_container.pass.cpp | 26 +++------- 7 files changed, 44 insertions(+), 118 deletions(-) diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp index cc80de8950738..227f881218248 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/copy_assign.pass.cpp @@ -26,12 +26,10 @@ int main(int, char**) { // test_allocator is not propagated using C = test_less; std::vector> ks({1, 3, 5}, test_allocator(6)); - std::vector> vs({2, 2, 1}, test_allocator(7)); + std::vector> vs({'2', '2', '1'}, test_allocator(7)); using M = std::flat_map; auto mo = M(ks, vs, C(5)); - auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, - C(3), - test_allocator(2)); + auto m = M({{3, '3'}, {4, '4'}, {5, '5'}}, C(3), test_allocator(2)); m = mo; assert(m.key_comp() == C(5)); @@ -53,12 +51,10 @@ int main(int, char**) { using Ks = std::vector>; using Vs = std::vector>; auto ks = Ks({1, 3, 5}, other_allocator(6)); - auto vs = Vs({2, 2, 1}, other_allocator(7)); + auto vs = Vs({'2', '2', '1'}, other_allocator(7)); using M = std::flat_map; auto mo = M(Ks(ks, other_allocator(6)), Vs(vs, other_allocator(7)), C(5)); - auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, - C(3), - other_allocator(2)); + auto m = M({{3, '3'}, {4, '4'}, {5, '5'}}, C(3), other_allocator(2)); m = mo; assert(m.key_comp() == C(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp index ad305ae41cdf2..924ce9e520b6c 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/move_assign.pass.cpp @@ -32,10 +32,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_map, std::vector>; - M mo = M({{1, static_cast(1)}, {2, static_cast(3)}, {3, static_cast(2)}}, C(5), A1(7)); + M mo = M({{1, '1'}, {2, '3'}, {3, '2'}}, C(5), A1(7)); M m = M({}, C(3), A1(7)); m = std::move(mo); - assert((m == M{{1, static_cast(1)}, {2, static_cast(3)}, {3, static_cast(2)}})); + assert((m == M{{1, '1'}, {2, '3'}, {3, '2'}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); @@ -47,15 +47,10 @@ int main(int, char**) { using A1 = other_allocator; using A2 = other_allocator; using M = std::flat_map, std::deque>; - M mo = M({{4, static_cast(5)}, {5, static_cast(4)}}, C(5), A1(7)); - M m = M({{1, static_cast(1)}, // - {2, static_cast(2)}, - {3, static_cast(3)}, - {4, static_cast(4)}}, - C(3), - A1(7)); + M mo = M({{4, '5'}, {5, '4'}}, C(5), A1(7)); + M m = M({{1, '1'}, {2, '2'}, {3, '3'}, {4, '4'}}, C(3), A1(7)); m = std::move(mo); - assert((m == M{{4, static_cast(5)}, {5, static_cast(4)}})); + assert((m == M{{4, '5'}, {5, '4'}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp index bde86ea2ddbe4..cb5b744984ab3 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_container.pass.cpp @@ -61,22 +61,16 @@ int main(int, char**) { // flat_map(sorted_unique_t, key_container_type , mapped_container_type) using M = std::flat_map; std::vector ks = {1, 2, 4, 10}; - std::vector vs = {4, 3, 2, 1}; + std::vector vs = {'4', '3', '2', '1'}; auto ks2 = ks; auto vs2 = vs; auto m = M(std::sorted_unique, ks, vs); - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {4, '2'}, {10, '1'}})); m = M(std::sorted_unique, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {4, '2'}, {10, '1'}})); // explicit(false) M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)}; @@ -89,19 +83,13 @@ int main(int, char**) { using Vs = std::deque>; using M = std::flat_map, Ks, Vs>; Ks ks = {10, 4, 2, 1}; - Vs vs = {1, 2, 3, 4}; + Vs vs = {'1', '2', '3', '4'}; auto m = M(std::sorted_unique, ks, vs); - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {4, '2'}, {10, '1'}})); m = M(std::sorted_unique, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {4, '2'}, {10, '1'}})); } { // flat_map(sorted_unique_t, key_container_type , mapped_container_type) @@ -122,13 +110,10 @@ int main(int, char**) { using C = test_less; using M = std::flat_map; std::vector ks = {1, 2, 4, 10}; - std::vector vs = {4, 3, 2, 1}; + std::vector vs = {'4', '3', '2', '1'}; auto m = M(std::sorted_unique, ks, vs, C(4)); - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {4, '2'}, {10, '1'}})); assert(m.key_comp() == C(4)); // explicit(false) diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp index f78f984dc6992..e21a0fcde8700 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/containers.pass.cpp @@ -69,18 +69,10 @@ int main(int, char**) { // flat_multimap(key_container_type , mapped_container_type) using M = std::flat_multimap; std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; - std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector vs = {'1', '2', '3', '4', '5', '6', '7', '8', '9'}; auto m = M(ks, vs); std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, '1'}, {1, '2'}, {1, '3'}, {2, '4'}, {2, '5'}, {2, '7'}, {3, '6'}, {3, '8'}, {3, '9'}}; assert(std::ranges::equal(m, expected)); // explicit(false) @@ -130,18 +122,10 @@ int main(int, char**) { using C = test_less; using M = std::flat_multimap; std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; - std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector vs = {'1', '2', '3', '4', '5', '6', '7', '8', '9'}; auto m = M(ks, vs, C(4)); std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, '1'}, {1, '2'}, {1, '3'}, {2, '4'}, {2, '5'}, {2, '7'}, {3, '6'}, {3, '8'}, {3, '9'}}; assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(4)); @@ -181,22 +165,13 @@ int main(int, char**) { } { // flat_multimap(key_container_type , mapped_container_type, key_compare, const Allocator&) - using C = test_less; - using A = test_allocator; - using M = std::flat_multimap, std::vector>; - std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; - std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; - auto m = M(ks, vs, C(4), A(5)); - std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + using C = test_less; + using A = test_allocator; + using M = std::flat_multimap, std::vector>; + std::vector ks = {1, 1, 1, 2, 2, 3, 2, 3, 3}; + std::vector vs = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + auto m = M(ks, vs, C(4), A(5)); + std::pair expected[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {2, 7}, {3, 6}, {3, 8}, {3, 9}}; assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(4)); assert(m.keys().get_allocator() == A(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp index 8a66a74690fe4..9dbdf94d0c413 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/copy_assign.pass.cpp @@ -26,12 +26,10 @@ int main(int, char**) { // test_allocator is not propagated using C = test_less; std::vector> ks({1, 1, 3, 3, 5}, test_allocator(6)); - std::vector> vs({1, 2, 3, 4, 5}, test_allocator(7)); + std::vector> vs({'1', '2', '3', '4', '5'}, test_allocator(7)); using M = std::flat_multimap; auto mo = M(ks, vs, C(5)); - auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, - C(3), - test_allocator(2)); + auto m = M({{3, '3'}, {4, '4'}, {5, '5'}}, C(3), test_allocator(2)); m = mo; assert(m.key_comp() == C(5)); @@ -53,12 +51,10 @@ int main(int, char**) { using Ks = std::vector>; using Vs = std::vector>; auto ks = Ks({1, 1, 3, 3, 5}, other_allocator(6)); - auto vs = Vs({2, 1, 3, 2, 1}, other_allocator(7)); + auto vs = Vs({'2', '1', '3', '2', '1'}, other_allocator(7)); using M = std::flat_multimap; auto mo = M(Ks(ks, other_allocator(6)), Vs(vs, other_allocator(7)), C(5)); - auto m = M({{3, static_cast(3)}, {4, static_cast(4)}, {5, static_cast(5)}}, - C(3), - other_allocator(2)); + auto m = M({{3, '3'}, {4, '4'}, {5, '5'}}, C(3), other_allocator(2)); m = mo; assert(m.key_comp() == C(5)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp index b033e5f3948cc..811e19c380a13 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp @@ -32,7 +32,7 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_multimap, std::vector>; - M mo = M({{1, static_cast(1)}, {1, static_cast(3)}, {3, static_cast(2)}}, C(5), A1(7)); + M mo = M({{1, '1'}, {1, '3')}, {3, '2'}}, C(5), A1(7)); M m = M({}, C(3), A1(7)); m = std::move(mo); assert((m == M{{1, 1}, {1, 3}, {3, 2}})); @@ -47,13 +47,8 @@ int main(int, char**) { using A1 = other_allocator; using A2 = other_allocator; using M = std::flat_multimap, std::deque>; - M mo = M({{4, static_cast(5)}, {4, static_cast(4)}}, C(5), A1(7)); - M m = M({{1, static_cast(1)}, // - {1, static_cast(2)}, - {1, static_cast(3)}, - {4, static_cast(4)}}, - C(3), - A1(7)); + M mo = M({{4, '5'}, {4, '4'}}, C(5), A1(7)); + M m = M({{1, '1'}, {1, '2'}, {1, '3'}, {4, '4'}}, C(3), A1(7)); m = std::move(mo); assert((m == M{{4, 5}, {4, 4}})); assert(m.key_comp() == C(5)); @@ -65,12 +60,8 @@ int main(int, char**) { { using A = min_allocator; using M = std::flat_multimap, std::vector, std::vector>; - M mo = M({{5, static_cast(1)}, {5, static_cast(2)}, {3, static_cast(3)}}, A()); - M m = M({{4, static_cast(4)}, // - {4, static_cast(3)}, - {4, static_cast(2)}, - {1, static_cast(1)}}, - A()); + M mo = M({{5, 1}, {5, 2}, {3, 3}}, A()); + M m = M({{4, 4}, {4, 3}, {4, 2}, {1, 1}}, A()); m = std::move(mo); assert((m == M{{5, 1}, {5, 2}, {3, 3}})); auto [ks, vs] = std::move(m).extract(); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp index 4534d5d0d249d..535e322baa34b 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp @@ -61,22 +61,16 @@ int main(int, char**) { // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type) using M = std::flat_multimap; std::vector ks = {1, 4, 4, 10}; - std::vector vs = {4, 3, 2, 1}; + std::vector vs = {'4', '3', '2', '1'}; auto ks2 = ks; auto vs2 = vs; auto m = M(std::sorted_equivalent, ks, vs); - assert((m == M{{1, static_cast(4)}, - {4, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {4, '3'}, {4, '2'}, {10, '1'}})); m = M(std::sorted_equivalent, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, static_cast(4)}, - {4, static_cast(3)}, - {4, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {4, '3'}, {4, '2'}, {10, '1'}})); // explicit(false) M m2 = {std::sorted_equivalent, std::move(ks2), std::move(vs2)}; @@ -89,12 +83,9 @@ int main(int, char**) { using Vs = std::deque>; using M = std::flat_multimap, Ks, Vs>; Ks ks = {10, 1, 1, 1}; - Vs vs = {1, 2, 3, 4}; + Vs vs = {'1', '2', '3', '4'}; auto m = M(std::sorted_equivalent, ks, vs); - assert((m == M{{1, static_cast(2)}, - {1, static_cast(3)}, - {1, static_cast(4)}, - {10, static_cast(1)}})); + assert((m == M{{1, '2'}, {1, '3'}, {1, '4'}, {10, '1'}})); m = M(std::sorted_equivalent, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from @@ -119,13 +110,10 @@ int main(int, char**) { using C = test_less; using M = std::flat_multimap; std::vector ks = {1, 2, 10, 10}; - std::vector vs = {4, 3, 2, 1}; + std::vector vs = {'4', '3', '2', '1'}; auto m = M(std::sorted_equivalent, ks, vs, C(4)); - assert((m == M{{1, static_cast(4)}, - {2, static_cast(3)}, - {10, static_cast(2)}, - {10, static_cast(1)}})); + assert((m == M{{1, '4'}, {2, '3'}, {10, '2'}, {10, '1'}})); assert(m.key_comp() == C(4)); // explicit(false) From f2d81b20488ddd711f5eb0623fd5e39279b84d60 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 26 Mar 2025 13:46:53 +0800 Subject: [PATCH 3/4] Use direct-list-initialization instead `static_cast` for `short` --- .../flat.map/flat.map.cons/deduct.pass.cpp | 42 +++-------- .../flat.map.cons/deduct_pmr.pass.cpp | 12 +--- .../flat.map.cons/initializer_list.pass.cpp | 51 +++---------- .../flat.map/flat.map.cons/iter_iter.pass.cpp | 20 +++--- .../flat.map/flat.map.cons/pmr.pass.cpp | 40 +++++------ .../flat.map/flat.map.cons/range.pass.cpp | 20 +++--- .../sorted_initializer_list.pass.cpp | 19 ++--- .../flat.map.cons/sorted_iter_iter.pass.cpp | 21 ++---- .../flat.multimap.cons/deduct.pass.cpp | 48 +++---------- .../flat.multimap.cons/deduct_pmr.pass.cpp | 16 +---- .../initializer_list.pass.cpp | 55 +++----------- .../flat.multimap.cons/iter_iter.pass.cpp | 36 +++++----- .../flat.multimap.cons/pmr.pass.cpp | 72 +++++++++---------- .../flat.multimap.cons/range.pass.cpp | 36 +++++----- .../sorted_initializer_list.pass.cpp | 19 ++--- .../sorted_iter_iter.pass.cpp | 17 ++--- 16 files changed, 171 insertions(+), 353 deletions(-) diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp index 3ca7aa1363856..84c5cba2b572c 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct.pass.cpp @@ -31,19 +31,19 @@ using PC = std::pair; void test_copy() { { - std::flat_map source = {{1, static_cast(2)}, {2, static_cast(3)}}; + std::flat_map source = {{1, short{2}}, {2, short{3}}}; std::flat_map s(source); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_map> source = {{1, static_cast(2)}, {2, static_cast(3)}}; + std::flat_map> source = {{1, short{2}}, {2, short{3}}}; std::flat_map s{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_map> source = {{1, static_cast(2)}, {2, static_cast(3)}}; + std::flat_map> source = {{1, short{2}}, {2, short{3}}}; std::flat_map s(source, std::allocator()); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); @@ -55,11 +55,7 @@ void test_containers() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({1, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 2, 5, 4}, test_allocator(0, 43)); - const std::pair expected[] = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {3, static_cast(5)}, - {INT_MAX, static_cast(4)}}; + const std::pair expected[] = {{1, short{1}}, {2, short{2}}, {3, short{5}}, {INT_MAX, short{4}}}; { std::flat_map s(ks, vs); @@ -99,11 +95,7 @@ void test_containers_compare() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator(0, 42)); std::deque> sorted_vs({4, 5, 2, 1}, test_allocator(0, 43)); - const std::pair expected[] = { - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}, - {2, static_cast(2)}, - {1, static_cast(1)}}; + const std::pair expected[] = {{INT_MAX, short{4}}, {3, short{5}}, {2, short{2}}, {1, short{1}}}; { std::flat_map s(ks, vs, std::greater()); @@ -287,16 +279,8 @@ void test_initializer_list_compare() { void test_from_range() { std::list> r = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {1, static_cast(1)}, - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}}; - const std::pair expected[] = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {3, static_cast(5)}, - {INT_MAX, static_cast(4)}}; + {1, short{1}}, {2, short{2}}, {1, short{1}}, {INT_MAX, short{4}}, {3, short{5}}}; + const std::pair expected[] = {{1, short{1}}, {2, short{2}}, {3, short{5}}, {INT_MAX, short{4}}}; { std::flat_map s(std::from_range, r); ASSERT_SAME_TYPE(decltype(s), std::flat_map>); @@ -319,16 +303,8 @@ void test_from_range() { void test_from_range_compare() { std::list> r = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {1, static_cast(1)}, - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}}; - const std::pair expected[] = { - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}, - {2, static_cast(2)}, - {1, static_cast(1)}}; + {1, short{1}}, {2, short{2}}, {1, short{1}}, {INT_MAX, short{4}}, {3, short{5}}}; + const std::pair expected[] = {{INT_MAX, short{4}}, {3, short{5}}, {2, short{2}}, {1, short{1}}}; { std::flat_map s(std::from_range, r, std::greater()); ASSERT_SAME_TYPE(decltype(s), std::flat_map>); diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp index e62b9049859aa..1da2c30fff503 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/deduct_pmr.pass.cpp @@ -35,11 +35,7 @@ void test_containers() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({1, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 2, 5, 4}, test_allocator(0, 43)); - const std::pair expected[] = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {3, static_cast(5)}, - {INT_MAX, static_cast(4)}}; + const std::pair expected[] = {{1, short{1}}, {2, short{2}}, {3, short{5}}, {INT_MAX, short{4}}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; @@ -73,11 +69,7 @@ void test_containers_compare() { std::deque> vs({1, 2, 1, 4, 5}, test_allocator(0, 43)); std::deque> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator(0, 42)); std::deque> sorted_vs({4, 5, 2, 1}, test_allocator(0, 43)); - const std::pair expected[] = { - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}, - {2, static_cast(2)}, - {1, static_cast(1)}}; + const std::pair expected[] = {{INT_MAX, short{4}}, {3, short{5}}, {2, short{2}}, {1, short{1}}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp index 5fa8b040a31e8..bedd403a067b8 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/initializer_list.pass.cpp @@ -82,18 +82,12 @@ int main(int, char**) { !std::is_constructible_v>, std::allocator>); } - std::pair expected[] = { - {1, static_cast(1)}, {2, static_cast(2)}, {3, static_cast(3)}, {5, static_cast(2)}}; + std::pair expected[] = {{1, short{1}}, {2, short{2}}, {3, short{3}}, {5, short{2}}}; { // flat_map(initializer_list); using M = std::flat_map; std::initializer_list> il = { - {5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + {5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; M m(il); assert(std::equal(m.begin(), m.end(), expected, expected + 4)); } @@ -101,23 +95,13 @@ int main(int, char**) { // flat_map(initializer_list); // explicit(false) using M = std::flat_map; - M m = {{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + M m = {{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; assert(std::equal(m.begin(), m.end(), expected, expected + 4)); } { // flat_map(initializer_list); using M = std::flat_map, std::deque>>; - M m = {{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + M m = {{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4)); } { @@ -144,25 +128,12 @@ int main(int, char**) { // flat_map(initializer_list, const key_compare&); using C = test_less; using M = std::flat_map; - auto m = - M({{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - C(10)); + auto m = M({{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, C(10)); assert(std::equal(m.begin(), m.end(), expected, expected + 4)); assert(m.key_comp() == C(10)); // explicit(false) - M m2 = {{{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - C(10)}; + M m2 = {{{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, C(10)}; assert(m2 == m); assert(m2.key_comp() == C(10)); } @@ -170,14 +141,8 @@ int main(int, char**) { // flat_map(initializer_list, const key_compare&); // Sorting uses the comparator that was passed in using M = std::flat_map, std::deque>>; - auto m = - M({{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - std::greater()); + auto m = M({{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, + std::greater()); assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4)); assert(m.key_comp()(2, 1) == true); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp index 6fb6eef67bb03..d940cfb0ebde9 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/iter_iter.pass.cpp @@ -59,16 +59,16 @@ int main(int, char**) { using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; - P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; + P expected[] = {{1, short{1}}, {2, short{4}}, {3, short{6}}}; { // flat_map(InputIterator , InputIterator) // cpp17_input_iterator diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp index d1c86bb077ed5..cf3d432ae22cc 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/pmr.pass.cpp @@ -168,16 +168,16 @@ int main(int, char**) { // flat_map(InputIterator first, InputIterator last, const Allocator& a); using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; - P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; + P expected[] = {{1, short{1}}, {2, short{4}}, {3, short{6}}}; { // cpp17 iterator using M = std::flat_map, std::pmr::vector, std::pmr::vector>; @@ -253,16 +253,16 @@ int main(int, char**) { // flat_map(from_range_t, R&&, const Alloc&); using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; - P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; + P expected[] = {{1, short{1}}, {2, short{4}}, {3, short{6}}}; { // input_range using M = std::flat_map, std::pmr::vector, std::pmr::vector>; diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp index c34109a1801ba..d3a5c83bebb86 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/range.pass.cpp @@ -119,16 +119,16 @@ int main(int, char**) { using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; - P expected[] = {{1, static_cast(1)}, {2, static_cast(4)}, {3, static_cast(6)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; + P expected[] = {{1, short{1}}, {2, short{4}}, {3, short{6}}}; { // flat_map(from_range_t, R&&) // input_range && !common diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp index 343cc57ad12bf..14dab70ea569b 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_initializer_list.pass.cpp @@ -31,11 +31,7 @@ #include "../../../test_compare.h" template -std::initializer_list> il = { - {static_cast(1), static_cast(1)}, - {static_cast(2), static_cast(2)}, - {static_cast(4), static_cast(4)}, - {static_cast(5), static_cast(5)}}; +std::initializer_list> il = {{T{1}, U{1}}, {T{2}, U{2}}, {T{4}, U{4}}, {T{5}, U{5}}}; const auto il1 = il; const auto il2 = il; @@ -144,8 +140,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::vector, std::deque>; auto m = M(std::sorted_unique, il2, A1(5)); - auto expected = M{ - {1, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; + auto expected = M{{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -163,10 +158,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::deque>; auto m = M(std::sorted_unique, il2, C(3), A1(5)); - assert((m == M{{1, static_cast(1)}, - {2, static_cast(2)}, - {4, static_cast(4)}, - {5, static_cast(5)}})); + assert((m == M{{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -178,10 +170,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_map, std::deque, std::vector>; M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor - assert((m == M{{static_cast(1), 1}, - {static_cast(2), 2}, - {static_cast(4), 4}, - {static_cast(5), 5}})); + assert((m == M{{short{1}, 1}, {short{2}, 2}, {short{4}, 4}, {short{5}, 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp index 3b27e684ec91b..a5398cbc1a305 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.map/flat.map.cons/sorted_iter_iter.pass.cpp @@ -125,11 +125,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_map, std::vector, std::deque>; - using P = std::pair; - P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; + using P = std::pair; + P ar[] = {{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}}; auto m = M(std::sorted_unique, ar, ar + 4, A1(5)); - auto expected = M{ - {1, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; + auto expected = M{{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -146,13 +145,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_map, std::deque>; - using P = std::pair; - P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; + using P = std::pair; + P ar[] = {{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}}; auto m = M(std::sorted_unique, ar, ar + 4, C(3), A1(5)); - assert((m == M{{1, static_cast(1)}, - {2, static_cast(2)}, - {4, static_cast(4)}, - {5, static_cast(5)}})); + assert((m == M{{1, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -166,10 +162,7 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}}; M m = {std::sorted_unique, ar, ar + 4, {}, A1(5)}; // implicit ctor - assert((m == M{{static_cast(1), 1}, - {static_cast(2), 2}, - {static_cast(4), 4}, - {static_cast(5), 5}})); + assert((m == M{{short{1}, 1}, {short{2}, 2}, {short{4}, 4}, {short{5}, 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp index 152786dc3b337..217f18e2106f4 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct.pass.cpp @@ -31,21 +31,19 @@ using PC = std::pair; void test_copy() { { - std::flat_multimap source = {{1, static_cast(2)}, {1, static_cast(3)}}; + std::flat_multimap source = {{1, short{2}}, {1, short{3}}}; std::flat_multimap s(source); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_multimap> source = { - {1, static_cast(2)}, {1, static_cast(3)}}; + std::flat_multimap> source = {{1, short{2}}, {1, short{3}}}; std::flat_multimap s{source}; // braces instead of parens ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); } { - std::flat_multimap> source = { - {1, static_cast(2)}, {1, static_cast(3)}}; + std::flat_multimap> source = {{1, short{2}}, {1, short{3}}}; std::flat_multimap s(source, std::allocator()); ASSERT_SAME_TYPE(decltype(s), decltype(source)); assert(s == source); @@ -58,13 +56,7 @@ void test_containers() { std::deque> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator(0, 43)); const std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(3)}, - {2, static_cast(2)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(4)}, - {INT_MAX, static_cast(3)}}; + {1, short{1}}, {1, short{3}}, {2, short{2}}, {2, short{4}}, {2, short{5}}, {3, short{4}}, {INT_MAX, short{3}}}; { std::flat_multimap s(ks, vs); @@ -105,13 +97,7 @@ void test_containers_compare() { std::deque> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator(0, 42)); std::deque> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator(0, 43)); const std::pair expected[] = { - {INT_MAX, static_cast(3)}, - {3, static_cast(4)}, - {2, static_cast(2)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {1, static_cast(1)}, - {1, static_cast(3)}}; + {INT_MAX, short{3}}, {3, short{4}}, {2, short{2}}, {2, short{4}}, {2, short{5}}, {1, short{1}}, {1, short{3}}}; { std::flat_multimap s(ks, vs, std::greater()); @@ -297,17 +283,9 @@ void test_initializer_list_compare() { void test_from_range() { std::list> r = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {1, static_cast(1)}, - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}}; + {1, short{1}}, {2, short{2}}, {1, short{1}}, {INT_MAX, short{4}}, {3, short{5}}}; const std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(1)}, - {2, static_cast(2)}, - {3, static_cast(5)}, - {INT_MAX, static_cast(4)}}; + {1, short{1}}, {1, short{1}}, {2, short{2}}, {3, short{5}}, {INT_MAX, short{4}}}; { std::flat_multimap s(std::from_range, r); ASSERT_SAME_TYPE(decltype(s), std::flat_multimap>); @@ -330,17 +308,9 @@ void test_from_range() { void test_from_range_compare() { std::list> r = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {1, static_cast(1)}, - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}}; + {1, short{1}}, {2, short{2}}, {1, short{1}}, {INT_MAX, short{4}}, {3, short{5}}}; const std::pair expected[] = { - {INT_MAX, static_cast(4)}, - {3, static_cast(5)}, - {2, static_cast(2)}, - {1, static_cast(1)}, - {1, static_cast(1)}}; + {INT_MAX, short{4}}, {3, short{5}}, {2, short{2}}, {1, short{1}}, {1, short{1}}}; { std::flat_multimap s(std::from_range, r, std::greater()); ASSERT_SAME_TYPE(decltype(s), std::flat_multimap>); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp index c775f937a3890..2ce9e2610b504 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/deduct_pmr.pass.cpp @@ -36,13 +36,7 @@ void test_containers() { std::deque> sorted_ks({1, 1, 2, 2, 2, 3, INT_MAX}, test_allocator(0, 42)); std::deque> sorted_vs({1, 3, 2, 4, 5, 4, 3}, test_allocator(0, 43)); const std::pair expected[] = { - {1, static_cast(1)}, - {1, static_cast(3)}, - {2, static_cast(2)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(4)}, - {INT_MAX, static_cast(3)}}; + {1, short{1}}, {1, short{3}}, {2, short{2}}, {2, short{4}}, {2, short{5}}, {3, short{4}}, {INT_MAX, short{3}}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; @@ -77,13 +71,7 @@ void test_containers_compare() { std::deque> sorted_ks({INT_MAX, 3, 2, 2, 2, 1, 1}, test_allocator(0, 42)); std::deque> sorted_vs({3, 4, 2, 4, 5, 1, 3}, test_allocator(0, 43)); const std::pair expected[] = { - {INT_MAX, static_cast(3)}, - {3, static_cast(4)}, - {2, static_cast(2)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {1, static_cast(1)}, - {1, static_cast(3)}}; + {INT_MAX, short{3}}, {3, short{4}}, {2, short{2}}, {2, short{4}}, {2, short{5}}, {1, short{1}}, {1, short{3}}}; { std::pmr::monotonic_buffer_resource mr; diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp index f81a9ebdfc87f..5be1c8e54c81a 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/initializer_list.pass.cpp @@ -84,22 +84,12 @@ int main(int, char**) { } std::pair expected[] = { - {1, static_cast(1)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {3, static_cast(3)}, - {5, static_cast(2)}}; + {1, short{1}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {3, short{3}}, {5, short{2}}}; { // flat_multimap(initializer_list); using M = std::flat_multimap; std::initializer_list> il = { - {5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + {5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; M m(il); assert(std::ranges::equal(m, expected)); } @@ -107,23 +97,13 @@ int main(int, char**) { // flat_multimap(initializer_list); // explicit(false) using M = std::flat_multimap; - M m = {{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + M m = {{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; assert(std::ranges::equal(m, expected)); } { // flat_multimap(initializer_list); using M = std::flat_multimap, std::deque>>; - M m = {{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}; + M m = {{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}; assert(std::equal(m.rbegin(), m.rend(), expected, expected + 6)); } { @@ -151,25 +131,12 @@ int main(int, char**) { // flat_multimap(initializer_list, const key_compare&); using C = test_less; using M = std::flat_multimap; - auto m = - M({{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - C(10)); + auto m = M({{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, C(10)); assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(10)); // explicit(false) - M m2 = {{{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - C(10)}; + M m2 = {{{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, C(10)}; assert(m2 == m); assert(m2.key_comp() == C(10)); } @@ -177,14 +144,8 @@ int main(int, char**) { // flat_multimap(initializer_list, const key_compare&); // Sorting uses the comparator that was passed in using M = std::flat_multimap, std::deque>>; - auto m = - M({{5, static_cast(2)}, - {2, static_cast(2)}, - {2, static_cast(2)}, - {3, static_cast(3)}, - {1, static_cast(1)}, - {3, static_cast(3)}}, - std::greater()); + auto m = M({{5, short{2}}, {2, short{2}}, {2, short{2}}, {3, short{3}}, {1, short{1}}, {3, short{3}}}, + std::greater()); assert(std::equal(m.rbegin(), m.rend(), expected, expected + 6)); assert(m.key_comp()(2, 1) == true); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp index 25c0cf04aaed6..0db3e8e5851ba 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/iter_iter.pass.cpp @@ -59,25 +59,25 @@ int main(int, char**) { using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; P expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {2, short{7}}, + {3, short{6}}, + {3, short{8}}, + {3, short{9}}}; { // flat_multimap(InputIterator , InputIterator) // cpp17_input_iterator diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp index c6c8a10cafc5a..7b75c5d57be23 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/pmr.pass.cpp @@ -168,25 +168,25 @@ int main(int, char**) { // flat_multimap(InputIterator first, InputIterator last, const Allocator& a); using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; P expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {2, short{7}}, + {3, short{6}}, + {3, short{8}}, + {3, short{9}}}; { // cpp17 iterator using M = std::flat_multimap, std::pmr::vector, std::pmr::vector>; @@ -262,25 +262,25 @@ int main(int, char**) { // flat_multimap(from_range_t, R&&, const Alloc&); using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; P expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {2, short{7}}, + {3, short{6}}, + {3, short{8}}, + {3, short{9}}}; { // input_range using M = std::flat_multimap, std::pmr::vector, std::pmr::vector>; diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp index d5e380dbfcd4d..542b517eeebd2 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/range.pass.cpp @@ -119,25 +119,25 @@ int main(int, char**) { using P = std::pair; P ar[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {3, static_cast(6)}, - {2, static_cast(7)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {3, short{6}}, + {2, short{7}}, + {3, short{8}}, + {3, short{9}}}; P expected[] = { - {1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(3)}, - {2, static_cast(4)}, - {2, static_cast(5)}, - {2, static_cast(7)}, - {3, static_cast(6)}, - {3, static_cast(8)}, - {3, static_cast(9)}}; + {1, short{1}}, + {1, short{2}}, + {1, short{3}}, + {2, short{4}}, + {2, short{5}}, + {2, short{7}}, + {3, short{6}}, + {3, short{8}}, + {3, short{9}}}; { // flat_multimap(from_range_t, R&&) // input_range && !common diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp index c33a259acd5e5..89c7119da389b 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_initializer_list.pass.cpp @@ -31,11 +31,7 @@ #include "../../../test_compare.h" template -std::initializer_list> il = { - {static_cast(1), static_cast(1)}, - {static_cast(4), static_cast(2)}, - {static_cast(4), static_cast(4)}, - {static_cast(5), static_cast(5)}}; +std::initializer_list> il = {{T{1}, U{1}}, {T{4}, U{2}}, {T{4}, U{4}}, {T{5}, U{5}}}; const auto il1 = il; const auto il2 = il; @@ -148,8 +144,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::vector, std::deque>; auto m = M(std::sorted_equivalent, il2, A1(5)); - auto expected = M{ - {1, static_cast(1)}, {4, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; + auto expected = M{{1, short{1}}, {4, short{2}}, {4, short{4}}, {5, short{5}}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -167,10 +162,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::deque>; auto m = M(std::sorted_equivalent, il2, C(3), A1(5)); - assert((m == M{{1, static_cast(1)}, - {4, static_cast(2)}, - {4, static_cast(4)}, - {5, static_cast(5)}})); + assert((m == M{{1, short{1}}, {4, short{2}}, {4, short{4}}, {5, short{5}}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -182,10 +174,7 @@ int main(int, char**) { using A2 = test_allocator; using M = std::flat_multimap, std::deque, std::vector>; M m = {std::sorted_equivalent, il3, {}, A1(5)}; // implicit ctor - assert((m == M{{static_cast(1), 1}, - {static_cast(4), 2}, - {static_cast(4), 4}, - {static_cast(5), 5}})); + assert((m == M{{short{1}, 1}, {short{4}, 2}, {short{4}, 4}, {short{5}, 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp index bd96fa91bc65f..5f532c435c797 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_iter_iter.pass.cpp @@ -130,8 +130,7 @@ int main(int, char**) { using P = std::pair; P ar[] = {{2, 1}, {2, 2}, {4, 4}, {5, 5}}; auto m = M(std::sorted_equivalent, ar, ar + 4, A1(5)); - auto expected = M{ - {2, static_cast(1)}, {2, static_cast(2)}, {4, static_cast(4)}, {5, static_cast(5)}}; + auto expected = M{{2, short{1}}, {2, short{2}}, {4, short{4}}, {5, short{5}}}; assert(m == expected); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -151,10 +150,7 @@ int main(int, char**) { using P = std::pair; P ar[] = {{1, 1}, {1, 2}, {1, 4}, {1, 5}}; auto m = M(std::sorted_equivalent, ar, ar + 4, C(3), A1(5)); - assert((m == M{{1, static_cast(1)}, - {1, static_cast(2)}, - {1, static_cast(4)}, - {1, static_cast(5)}})); + assert((m == M{{1, short{1}}, {1, short{2}}, {1, short{4}}, {1, short{5}}})); assert(m.key_comp() == C(3)); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); @@ -165,11 +161,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_multimap, std::deque, std::vector>; - using P = std::pair; - P ar[] = { - {static_cast(1), 1}, {static_cast(1), 2}, {static_cast(1), 4}, {static_cast(1), 5}}; - M m = {std::sorted_equivalent, ar, ar + 4, {}, A1(5)}; // implicit ctor - assert((m == M{{1, 1}, {1, 2}, {1, 4}, {1, 5}})); + using P = std::pair; + P ar[] = {{short{1}, 1}, {short{1}, 2}, {short{1}, 4}, {short{1}, 5}}; + M m = {std::sorted_equivalent, ar, ar + 4, {}, A1(5)}; // implicit ctor + assert((m == M{{short{1}, 1}, {short{1}, 2}, {short{1}, 4}, {short{1}, 5}})); assert(m.keys().get_allocator() == A1(5)); assert(m.values().get_allocator() == A2(5)); } From 631a31c7b9e014ce82541f6824eb3bfec74e4dce Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Wed, 26 Mar 2025 14:05:29 +0800 Subject: [PATCH 4/4] Fixup for `char` literals --- .../flat.multimap/flat.multimap.cons/move_assign.pass.cpp | 6 +++--- .../flat.multimap.cons/sorted_container.pass.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp index 811e19c380a13..86e7cdd433de6 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/move_assign.pass.cpp @@ -32,10 +32,10 @@ int main(int, char**) { using A1 = test_allocator; using A2 = test_allocator; using M = std::flat_multimap, std::vector>; - M mo = M({{1, '1'}, {1, '3')}, {3, '2'}}, C(5), A1(7)); + M mo = M({{1, '1'}, {1, '3'}, {3, '2'}}, C(5), A1(7)); M m = M({}, C(3), A1(7)); m = std::move(mo); - assert((m == M{{1, 1}, {1, 3}, {3, 2}})); + assert((m == M{{1, '1'}, {1, '3'}, {3, '2'}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); @@ -50,7 +50,7 @@ int main(int, char**) { M mo = M({{4, '5'}, {4, '4'}}, C(5), A1(7)); M m = M({{1, '1'}, {1, '2'}, {1, '3'}, {4, '4'}}, C(3), A1(7)); m = std::move(mo); - assert((m == M{{4, 5}, {4, 4}})); + assert((m == M{{4, '5'}, {4, '4'}})); assert(m.key_comp() == C(5)); auto [ks, vs] = std::move(m).extract(); assert(ks.get_allocator() == A1(7)); diff --git a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp index 535e322baa34b..518904801f2bd 100644 --- a/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp +++ b/libcxx/test/std/containers/container.adaptors/flat.multimap/flat.multimap.cons/sorted_container.pass.cpp @@ -89,7 +89,7 @@ int main(int, char**) { m = M(std::sorted_equivalent, std::move(ks), std::move(vs)); assert(ks.empty()); // it was moved-from assert(vs.empty()); // it was moved-from - assert((m == M{{1, 2}, {1, 3}, {1, 4}, {10, 1}})); + assert((m == M{{1, '2'}, {1, '3'}, {1, '4'}, {10, '1'}})); } { // flat_multimap(sorted_equivalent_t, key_container_type , mapped_container_type)