//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 // UNSUPPORTED: availability-pmr-missing // #include #include #include #include #include #include #include #include #include #include #include #include #include #include "test_allocator.h" using P = std::pair; using PC = std::pair; void test_containers() { std::deque> ks({1, 2, 1, INT_MAX, 3}, test_allocator(0, 42)); 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}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(ks.begin(), ks.end(), &mr); std::pmr::deque pvs(vs.begin(), vs.end(), &mr); std::flat_map s(std::move(pks), std::move(pvs), &mr2); ASSERT_SAME_TYPE( decltype(s), std::flat_map, std::pmr::deque, std::pmr::deque>); assert(std::ranges::equal(s, expected)); assert(s.keys().get_allocator().resource() == &mr2); assert(s.values().get_allocator().resource() == &mr2); } { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(sorted_ks.begin(), sorted_ks.end(), &mr); std::pmr::deque pvs(sorted_vs.begin(), sorted_vs.end(), &mr); std::flat_map s(std::sorted_unique, std::move(pks), std::move(pvs), &mr2); ASSERT_SAME_TYPE( decltype(s), std::flat_map, std::pmr::deque, std::pmr::deque>); assert(std::ranges::equal(s, expected)); assert(s.keys().get_allocator().resource() == &mr2); assert(s.values().get_allocator().resource() == &mr2); } } void test_containers_compare() { std::deque> ks({1, 2, 1, INT_MAX, 3}, test_allocator(0, 42)); 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}}; { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(ks.begin(), ks.end(), &mr); std::pmr::deque pvs(vs.begin(), vs.end(), &mr); std::flat_map s(std::move(pks), std::move(pvs), std::greater(), &mr2); ASSERT_SAME_TYPE( decltype(s), std::flat_map, std::pmr::deque, std::pmr::deque>); assert(std::ranges::equal(s, expected)); assert(s.keys().get_allocator().resource() == &mr2); assert(s.values().get_allocator().resource() == &mr2); } { std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(sorted_ks.begin(), sorted_ks.end(), &mr); std::pmr::deque pvs(sorted_vs.begin(), sorted_vs.end(), &mr); std::flat_map s(std::sorted_unique, std::move(pks), std::move(pvs), std::greater(), &mr2); ASSERT_SAME_TYPE( decltype(s), std::flat_map, std::pmr::deque, std::pmr::deque>); assert(std::ranges::equal(s, expected)); assert(s.keys().get_allocator().resource() == &mr2); assert(s.values().get_allocator().resource() == &mr2); } } int main(int, char**) { test_containers(); test_containers_compare(); return 0; }