| 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=(flat_map&&); |
| 14 | |
| 15 | #include <algorithm> |
| 16 | #include <deque> |
| 17 | #include <flat_map> |
| 18 | #include <functional> |
| 19 | #include <string> |
| 20 | #include <utility> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | #include "MoveOnly.h" |
| 25 | #include "../../../test_compare.h" |
| 26 | #include "test_allocator.h" |
| 27 | #include "min_allocator.h" |
| 28 | |
| 29 | int main(int, char**) { |
| 30 | { |
| 31 | using C = test_less<int>; |
| 32 | using A1 = test_allocator<int>; |
| 33 | using A2 = test_allocator<char>; |
| 34 | using M = std::flat_map<int, char, C, std::vector<int, A1>, std::vector<char, A2>>; |
| 35 | M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7)); |
| 36 | M m = M({}, C(3), A1(7)); |
| 37 | m = std::move(mo); |
| 38 | assert((m == M{{1, 1}, {2, 3}, {3, 2}})); |
| 39 | assert(m.key_comp() == C(5)); |
| 40 | auto [ks, vs] = std::move(m).extract(); |
| 41 | assert(ks.get_allocator() == A1(7)); |
| 42 | assert(vs.get_allocator() == A2(7)); |
| 43 | assert(mo.empty()); |
| 44 | } |
| 45 | { |
| 46 | using C = test_less<int>; |
| 47 | using A1 = other_allocator<int>; |
| 48 | using A2 = other_allocator<char>; |
| 49 | using M = std::flat_map<int, char, C, std::deque<int, A1>, std::deque<char, A2>>; |
| 50 | M mo = M({{4, 5}, {5, 4}}, C(5), A1(7)); |
| 51 | M m = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7)); |
| 52 | m = std::move(mo); |
| 53 | assert((m == M{{4, 5}, {5, 4}})); |
| 54 | assert(m.key_comp() == C(5)); |
| 55 | auto [ks, vs] = std::move(m).extract(); |
| 56 | assert(ks.get_allocator() == A1(7)); |
| 57 | assert(vs.get_allocator() == A2(7)); |
| 58 | assert(mo.empty()); |
| 59 | } |
| 60 | { |
| 61 | using A = min_allocator<int>; |
| 62 | using M = std::flat_map<int, int, std::greater<int>, std::vector<int, A>, std::vector<int, A>>; |
| 63 | M mo = M({{5, 1}, {4, 2}, {3, 3}}, A()); |
| 64 | M m = M({{4, 4}, {3, 3}, {2, 2}, {1, 1}}, A()); |
| 65 | m = std::move(mo); |
| 66 | assert((m == M{{5, 1}, {4, 2}, {3, 3}})); |
| 67 | auto [ks, vs] = std::move(m).extract(); |
| 68 | assert(ks.get_allocator() == A()); |
| 69 | assert(vs.get_allocator() == A()); |
| 70 | assert(mo.empty()); |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |