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 | // void swap(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 NoExceptMemberSwap = requires(T t1, T t2) { |
31 | { t1.swap(t2) } noexcept; |
32 | }; |
33 | |
34 | static_assert(NoExceptMemberSwap<std::flat_multiset<int>>); |
35 | #ifndef TEST_HAS_NO_EXCEPTIONS |
36 | static_assert(NoExceptMemberSwap<std::flat_multiset<int, std::less<int>, ThrowOnMoveContainer<int>>>); |
37 | #endif |
38 | |
39 | template <class KeyContainer> |
40 | void test_one() { |
41 | using Key = typename KeyContainer::value_type; |
42 | using M = std::flat_multiset<Key, std::less<Key>, KeyContainer>; |
43 | { |
44 | M m1; |
45 | M m2; |
46 | M m1_save = m1; |
47 | M m2_save = m2; |
48 | m1.swap(m2); |
49 | assert(m1 == m2_save); |
50 | assert(m2 == m1_save); |
51 | } |
52 | { |
53 | int ar2[] = {5, 5, 7, 7, 9, 10, 11, 12}; |
54 | M m1; |
55 | M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0])); |
56 | M m1_save = m1; |
57 | M m2_save = m2; |
58 | m1.swap(m2); |
59 | assert(m1 == m2_save); |
60 | assert(m2 == m1_save); |
61 | } |
62 | { |
63 | int ar1[] = {1, 1, 3, 4}; |
64 | M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0])); |
65 | M m2; |
66 | M m1_save = m1; |
67 | M m2_save = m2; |
68 | m1.swap(m2); |
69 | assert(m1 == m2_save); |
70 | assert(m2 == m1_save); |
71 | } |
72 | { |
73 | int ar1[] = {1, 1, 3, 4}; |
74 | int ar2[] = {5, 5, 7, 8, 9, 10, 11, 12}; |
75 | M m1(ar1, ar1 + sizeof(ar1) / sizeof(ar1[0])); |
76 | M m2(ar2, ar2 + sizeof(ar2) / sizeof(ar2[0])); |
77 | M m1_save = m1; |
78 | M m2_save = m2; |
79 | m1.swap(m2); |
80 | assert(m1 == m2_save); |
81 | assert(m2 == m1_save); |
82 | } |
83 | } |
84 | |
85 | void test() { |
86 | test_one<std::vector<int>>(); |
87 | test_one<std::deque<int>>(); |
88 | test_one<MinSequenceContainer<int>>(); |
89 | test_one<std::vector<int, min_allocator<int>>>(); |
90 | } |
91 | |
92 | int main(int, char**) { |
93 | test(); |
94 | |
95 | return 0; |
96 | } |
97 | |