//===----------------------------------------------------------------------===// // // 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 // flat_map(InputIterator first, InputIterator last, const key_compare& comp = key_compare()); // template // flat_map(InputIterator first, InputIterator last, const Allocator& a); // template // flat_map(InputIterator first, InputIterator last, const key_compare& comp, const Allocator& a); #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 "../helpers.h" #include "../../../test_compare.h" 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(InputIterator , InputIterator) // cpp17_input_iterator using M = std::flat_map, KeyContainer, ValueContainer>; auto m = M(cpp17_input_iterator(ar), cpp17_input_iterator(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 = {cpp17_input_iterator(ar), cpp17_input_iterator(ar + 9)}; assert(m2 == m); } { // flat_map(InputIterator , InputIterator) // greater using M = std::flat_map, KeyContainer, ValueContainer>; auto m = M(cpp17_input_iterator(ar), cpp17_input_iterator(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(InputIterator , InputIterator) // Test when the operands are of array type (also contiguous iterator type) using M = std::flat_map, KeyContainer, ValueContainer>; auto m = M(ar, ar); assert(m.empty()); } { // flat_map(InputIterator , InputIterator, const key_compare&) using C = test_less; using M = std::flat_map; auto m = M(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 = {ar, ar + 9, C(3)}; assert(m2 == m); assert(m2.key_comp() == C(3)); } } template