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 | // class flat_multimap |
14 | |
15 | // void insert(initializer_list<value_type> il); |
16 | |
17 | #include <flat_map> |
18 | #include <cassert> |
19 | #include <functional> |
20 | #include <deque> |
21 | |
22 | #include "MinSequenceContainer.h" |
23 | #include "../helpers.h" |
24 | #include "test_macros.h" |
25 | #include "min_allocator.h" |
26 | |
27 | template <class KeyContainer, class ValueContainer> |
28 | void test() { |
29 | using Key = typename KeyContainer::value_type; |
30 | using Value = typename ValueContainer::value_type; |
31 | using M = std::flat_multimap<Key, Value, std::less<Key>, KeyContainer, ValueContainer>; |
32 | using V = std::pair<int, double>; |
33 | |
34 | M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}}; |
35 | m.insert({ |
36 | {4, 1}, |
37 | {4, 1.5}, |
38 | {4, 2}, |
39 | {1, 1}, |
40 | {1, 1.5}, |
41 | {1, 2}, |
42 | {2, 1}, |
43 | {2, 1.5}, |
44 | {2, 2}, |
45 | }); |
46 | assert(m.size() == 15); |
47 | std::vector<V> expected = { |
48 | {1, 1}, |
49 | {1, 1.5}, |
50 | {1, 2}, |
51 | {1, 1}, |
52 | {1, 1.5}, |
53 | {1, 2}, |
54 | {2, 1}, |
55 | {2, 1.5}, |
56 | {2, 2}, |
57 | {3, 1}, |
58 | {3, 1.5}, |
59 | {3, 2}, |
60 | {4, 1}, |
61 | {4, 1.5}, |
62 | {4, 2}, |
63 | }; |
64 | assert(std::ranges::equal(m, expected)); |
65 | } |
66 | |
67 | int main(int, char**) { |
68 | test<std::vector<int>, std::vector<double>>(); |
69 | test<std::deque<int>, std::vector<double>>(); |
70 | test<MinSequenceContainer<int>, MinSequenceContainer<double>>(); |
71 | test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>(); |
72 | |
73 | { |
74 | auto insert_func = [](auto& m, const auto& newValues) { |
75 | using FlatMap = std::decay_t<decltype(m)>; |
76 | using value_type = typename FlatMap::value_type; |
77 | std::initializer_list<value_type> il = {{newValues[0].first, newValues[0].second}}; |
78 | m.insert(il); |
79 | }; |
80 | test_insert_range_exception_guarantee(insert_function&: insert_func); |
81 | } |
82 | return 0; |
83 | } |
84 | |