| 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_set> |
| 12 | |
| 13 | // friend void swap(flat_multiset& x, flat_multiset& y) noexcept |
| 14 | |
| 15 | #include <flat_set> |
| 16 | #include <cassert> |
| 17 | #include <deque> |
| 18 | #include <functional> |
| 19 | #include <vector> |
| 20 | |
| 21 | #include "MinSequenceContainer.h" |
| 22 | #include "MoveOnly.h" |
| 23 | #include "min_allocator.h" |
| 24 | #include "test_macros.h" |
| 25 | #include "../helpers.h" |
| 26 | |
| 27 | // test noexcept |
| 28 | |
| 29 | template <class T> |
| 30 | concept NoExceptAdlSwap = requires(T t1, T t2) { |
| 31 | { swap(t1, t2) } noexcept; |
| 32 | }; |
| 33 | |
| 34 | static_assert(NoExceptAdlSwap<std::flat_multiset<int>>); |
| 35 | |
| 36 | #ifndef TEST_HAS_NO_EXCEPTIONS |
| 37 | static_assert(NoExceptAdlSwap<std::flat_multiset<int, std::less<int>, ThrowOnMoveContainer<int>>>); |
| 38 | #endif |
| 39 | |
| 40 | template <class KeyContainer> |
| 41 | void test_one() { |
| 42 | using Key = typename KeyContainer::value_type; |
| 43 | using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>; |
| 44 | |
| 45 | { |
| 46 | M m1; |
| 47 | M m2; |
| 48 | M m1_save = m1; |
| 49 | M m2_save = m2; |
| 50 | swap(m1, m2); |
| 51 | assert(m1 == m2_save); |
| 52 | assert(m2 == m1_save); |
| 53 | } |
| 54 | { |
| 55 | int ar2[] = {5, 5, 7, 8, 8, 10, 11, 12}; |
| 56 | M m1; |
| 57 | M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0])); |
| 58 | M m1_save = m1; |
| 59 | M m2_save = m2; |
| 60 | swap(m1, m2); |
| 61 | assert(m1 == m2_save); |
| 62 | assert(m2 == m1_save); |
| 63 | } |
| 64 | { |
| 65 | int ar1[] = {1, 1, 3, 4}; |
| 66 | M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0])); |
| 67 | M m2; |
| 68 | M m1_save = m1; |
| 69 | M m2_save = m2; |
| 70 | swap(m1, m2); |
| 71 | assert(m1 == m2_save); |
| 72 | assert(m2 == m1_save); |
| 73 | } |
| 74 | { |
| 75 | int ar1[] = {1, 1, 3, 4}; |
| 76 | int ar2[] = {5, 5, 7, 8, 9, 10, 11, 12}; |
| 77 | M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0])); |
| 78 | M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0])); |
| 79 | M m1_save = m1; |
| 80 | M m2_save = m2; |
| 81 | swap(m1, m2); |
| 82 | assert(m1 == m2_save); |
| 83 | assert(m2 == m1_save); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void test() { |
| 88 | test_one<std::vector<int>>(); |
| 89 | test_one<std::deque<int>>(); |
| 90 | test_one<MinSequenceContainer<int>>(); |
| 91 | test_one<std::vector<int, min_allocator<int>>>(); |
| 92 | } |
| 93 | |
| 94 | int main(int, char**) { |
| 95 | test(); |
| 96 | |
| 97 | return 0; |
| 98 | } |
| 99 | |