//===----------------------------------------------------------------------===// // // 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_map(from_range_t, R&&) // template R> // flat_map(from_range_t, R&&, const key_compare&) // template R, class Alloc> // flat_map(from_range_t, R&&, const Alloc&); // template R, class Alloc> // flat_map(from_range_t, R&&, const key_compare&, const Alloc&); #include #include #include #include #include #include #include "min_allocator.h" #include "MinSequenceContainer.h" #include "test_allocator.h" #include "test_iterators.h" #include "test_macros.h" #include "../helpers.h" #include "../../../test_compare.h" // test constraint container-compatible-range template using RangeOf = std::ranges::subrange; using Map = std::flat_map; static_assert(std::is_constructible_v>>); 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::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::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>); static_assert(!std::is_constructible_v, std::less, std::allocator>); template constexpr void test() { using Key = typename KeyContainer::value_type; using Value = typename ValueContainer::value_type; using P = std::pair; P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}}; { // flat_map(from_range_t, R&&) // input_range && !common using M = std::flat_map, KeyContainer, ValueContainer>; 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.keys(), KeyContainer{1, 2, 3})); check_possible_values( m.values(), std::vector>{ {1, 2, 3}, {4, 5, 7}, {6, 8, 9}, }); // explicit(false) M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))}; assert(m2 == m); } { // flat_map(from_range_t, R&&) // greater using M = std::flat_map, KeyContainer, ValueContainer>; 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.keys(), KeyContainer{3, 2, 1})); check_possible_values( m.values(), std::vector>{ {6, 8, 9}, {4, 5, 7}, {1, 2, 3}, }); } { // flat_map(from_range_t, R&&) // contiguous range using M = std::flat_map, KeyContainer, ValueContainer>; using R = std::ranges::subrange; auto m = M(std::from_range, R(ar, ar + 9)); assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3})); check_possible_values( m.values(), std::vector>{ {1, 2, 3}, {4, 5, 7}, {6, 8, 9}, }); } { // flat_map(from_range_t, R&&, const key_compare&) using C = test_less; using M = std::flat_map; using R = std::ranges::subrange; auto m = M(std::from_range, R(ar, ar + 9), C(3)); assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3})); check_possible_values( m.values(), std::vector>{ {1, 2, 3}, {4, 5, 7}, {6, 8, 9}, }); 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