| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 | |
| 11 | // <flat_map> |
| 12 | |
| 13 | // flat_map& operator=(initializer_list<value_type> il); |
| 14 | |
| 15 | #include <algorithm> |
| 16 | #include <cassert> |
| 17 | #include <deque> |
| 18 | #include <flat_map> |
| 19 | #include <functional> |
| 20 | #include <ranges> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "MinSequenceContainer.h" |
| 24 | #include "test_macros.h" |
| 25 | #include "min_allocator.h" |
| 26 | #include "test_allocator.h" |
| 27 | |
| 28 | template <class KeyContainer, class ValueContainer> |
| 29 | void test() { |
| 30 | using Key = typename KeyContainer::value_type; |
| 31 | using Value = typename ValueContainer::value_type; |
| 32 | using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>; |
| 33 | { |
| 34 | M m = {{8, 8}, {10, 10}}; |
| 35 | assert(m.size() == 2); |
| 36 | m = {{3, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}, {4, 0}, {3, 2}, {5, 0}, {6, 0}, {5, 1}}; |
| 37 | std::pair<int, int> expected[] = {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}}; |
| 38 | assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>)); |
| 39 | LIBCPP_ASSERT(std::ranges::equal(m, expected)); |
| 40 | } |
| 41 | { |
| 42 | M m = {{10, 1}, {8, 1}}; |
| 43 | assert(m.size() == 2); |
| 44 | m = {{3, 2}}; |
| 45 | std::pair<double, double> expected[] = {{3, 2}}; |
| 46 | assert(std::ranges::equal(m, expected)); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | int main(int, char**) { |
| 51 | test<std::vector<int>, std::vector<int>>(); |
| 52 | test<std::vector<int>, std::vector<double>>(); |
| 53 | test<std::deque<int>, std::vector<double>>(); |
| 54 | test<MinSequenceContainer<int>, MinSequenceContainer<double>>(); |
| 55 | test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>(); |
| 56 | test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |