//===----------------------------------------------------------------------===// // // 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; int main(int, char**) { { std::deque> ks({1, 2, 1, INT_MAX, 3}, test_allocator(0, 42)); std::deque> sorted_ks({1, 2, 3, INT_MAX}, test_allocator(0, 42)); const int expected[] = {1, 2, 3, INT_MAX}; { // template // flat_set(KeyContainer, Allocator) // -> flat_set, KeyContainer>; std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(ks.begin(), ks.end(), &mr); std::flat_set s(std::move(pks), &mr2); ASSERT_SAME_TYPE(decltype(s), std::flat_set, std::pmr::deque>); assert(std::ranges::equal(s, expected)); auto keys = std::move(s).extract(); assert(keys.get_allocator().resource() == &mr2); } { // template // flat_set(sorted_unique_t, KeyContainer, Allocator) // -> flat_set, KeyContainer>; std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(sorted_ks.begin(), sorted_ks.end(), &mr); std::flat_set s(std::sorted_unique, std::move(pks), &mr2); ASSERT_SAME_TYPE(decltype(s), std::flat_set, std::pmr::deque>); assert(std::ranges::equal(s, expected)); auto keys = std::move(s).extract(); assert(keys.get_allocator().resource() == &mr2); } } { std::deque> ks({1, 2, 1, INT_MAX, 3}, test_allocator(0, 42)); std::deque> sorted_ks({INT_MAX, 3, 2, 1}, test_allocator(0, 42)); const int expected[] = {INT_MAX, 3, 2, 1}; { // template // flat_set(KeyContainer, Compare, Allocator) // -> flat_set; std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(ks.begin(), ks.end(), &mr); std::flat_set s(std::move(pks), std::greater(), &mr2); ASSERT_SAME_TYPE(decltype(s), std::flat_set, std::pmr::deque>); assert(std::ranges::equal(s, expected)); auto keys = std::move(s).extract(); assert(keys.get_allocator().resource() == &mr2); } { // template // flat_set(sorted_unique_t, KeyContainer, Compare, Allocator) // -> flat_set; std::pmr::monotonic_buffer_resource mr; std::pmr::monotonic_buffer_resource mr2; std::pmr::deque pks(sorted_ks.begin(), sorted_ks.end(), &mr); std::flat_set s(std::sorted_unique, std::move(pks), std::greater(), &mr2); ASSERT_SAME_TYPE(decltype(s), std::flat_set, std::pmr::deque>); assert(std::ranges::equal(s, expected)); auto keys = std::move(s).extract(); assert(keys.get_allocator().resource() == &mr2); } } return 0; }