| 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_multimap& operator=(const flat_multimap& m); |
| 14 | |
| 15 | #include <deque> |
| 16 | #include <flat_map> |
| 17 | #include <functional> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "../../../test_compare.h" |
| 22 | #include "test_allocator.h" |
| 23 | |
| 24 | int main(int, char**) { |
| 25 | { |
| 26 | // test_allocator is not propagated |
| 27 | using C = test_less<int>; |
| 28 | std::vector<int, test_allocator<int>> ks({1, 1, 3, 3, 5}, test_allocator<int>(6)); |
| 29 | std::vector<char, test_allocator<char>> vs({1, 2, 3, 4, 5}, test_allocator<char>(7)); |
| 30 | using M = std::flat_multimap<int, char, C, decltype(ks), decltype(vs)>; |
| 31 | auto mo = M(ks, vs, C(5)); |
| 32 | auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator<int>(2)); |
| 33 | m = mo; |
| 34 | |
| 35 | assert(m.key_comp() == C(5)); |
| 36 | assert(m.keys() == ks); |
| 37 | assert(m.values() == vs); |
| 38 | assert(m.keys().get_allocator() == test_allocator<int>(2)); |
| 39 | assert(m.values().get_allocator() == test_allocator<char>(2)); |
| 40 | |
| 41 | // mo is unchanged |
| 42 | assert(mo.key_comp() == C(5)); |
| 43 | assert(mo.keys() == ks); |
| 44 | assert(mo.values() == vs); |
| 45 | assert(mo.keys().get_allocator() == test_allocator<int>(6)); |
| 46 | assert(mo.values().get_allocator() == test_allocator<char>(7)); |
| 47 | } |
| 48 | { |
| 49 | // other_allocator is propagated |
| 50 | using C = test_less<int>; |
| 51 | using Ks = std::vector<int, other_allocator<int>>; |
| 52 | using Vs = std::vector<char, other_allocator<char>>; |
| 53 | auto ks = Ks({1, 1, 3, 3, 5}, other_allocator<int>(6)); |
| 54 | auto vs = Vs({2, 1, 3, 2, 1}, other_allocator<char>(7)); |
| 55 | using M = std::flat_multimap<int, char, C, Ks, Vs>; |
| 56 | auto mo = M(Ks(ks, other_allocator<int>(6)), Vs(vs, other_allocator<int>(7)), C(5)); |
| 57 | auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), other_allocator<int>(2)); |
| 58 | m = mo; |
| 59 | |
| 60 | assert(m.key_comp() == C(5)); |
| 61 | assert(m.keys() == ks); |
| 62 | assert(m.values() == vs); |
| 63 | assert(m.keys().get_allocator() == other_allocator<int>(6)); |
| 64 | assert(m.values().get_allocator() == other_allocator<char>(7)); |
| 65 | |
| 66 | // mo is unchanged |
| 67 | assert(mo.key_comp() == C(5)); |
| 68 | assert(mo.keys() == ks); |
| 69 | assert(mo.values() == vs); |
| 70 | assert(mo.keys().get_allocator() == other_allocator<int>(6)); |
| 71 | assert(mo.values().get_allocator() == other_allocator<char>(7)); |
| 72 | } |
| 73 | { |
| 74 | // self-assignment |
| 75 | using M = std::flat_multimap<int, int>; |
| 76 | M m = {{1, 1}, {3, 4}}; |
| 77 | m = static_cast<const M&>(m); |
| 78 | assert((m == M{{1, 1}, {3, 4}})); |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | |