//===----------------------------------------------------------------------===// // // 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 // // template R> // flat_set(from_range_t, R&&) // template R> // flat_set(from_range_t, R&&, const key_compare&) // template R, class Alloc> // flat_set(from_range_t, R&&, const Alloc&); // template R, class Alloc> // flat_set(from_range_t, R&&, const key_compare&, const Alloc&); #include #include #include #include #include #include #include "MinSequenceContainer.h" #include "min_allocator.h" #include "test_allocator.h" #include "test_iterators.h" #include "test_macros.h" #include "../../../test_compare.h" // test constraint container-compatible-range template using RangeOf = std::ranges::subrange; using Set = std::flat_set; static_assert(std::is_constructible_v>); static_assert(std::is_constructible_v>); static_assert(!std::is_constructible_v>>); static_assert(std::is_constructible_v, std::less>); static_assert(std::is_constructible_v, std::less>); static_assert(!std::is_constructible_v>, std::less>); static_assert(std::is_constructible_v, std::allocator>); static_assert(std::is_constructible_v, std::allocator>); static_assert(!std::is_constructible_v>, std::allocator>); static_assert(std::is_constructible_v, std::less, std::allocator>); static_assert(std::is_constructible_v, std::less, std::allocator>); static_assert( !std:: is_constructible_v>, std::less, std::allocator>); template constexpr void test() { int ar[] = {1, 1, 1, 2, 2, 3, 2, 3, 3}; int expected[] = {1, 2, 3}; { // flat_set(from_range_t, R&&) // input_range && !common using M = std::flat_set, KeyContainer>; using Iter = cpp20_input_iterator; using Sent = sentinel_wrapper; using R = std::ranges::subrange; auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))); assert(std::ranges::equal(m, expected)); LIBCPP_ASSERT(std::ranges::equal(m, expected)); // explicit(false) M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))}; assert(m2 == m); } { // flat_set(from_range_t, R&&) // greater using M = std::flat_set, KeyContainer>; using Iter = cpp20_input_iterator; using Sent = sentinel_wrapper; using R = std::ranges::subrange; auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))); assert(std::ranges::equal(m, KeyContainer{3, 2, 1})); } { // flat_set(from_range_t, R&&) // contiguous range using M = std::flat_set, KeyContainer>; using R = std::ranges::subrange; auto m = M(std::from_range, R(ar, ar + 9)); assert(std::ranges::equal(m, expected)); } { // flat_set(from_range_t, R&&, const key_compare&) using C = test_less; using M = std::flat_set; using R = std::ranges::subrange; auto m = M(std::from_range, R(ar, ar + 9), C(3)); assert(std::ranges::equal(m, expected)); assert(m.key_comp() == C(3)); // explicit(false) M m2 = {std::from_range, R(ar, ar + 9), C(3)}; assert(m2 == m); assert(m2.key_comp() == C(3)); } } template