1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <set> 11 12 // class multiset 13 14 // void swap(multiset& m); 15 16 #include <set> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 21 int main() 22 { 23 { 24 typedef int V; 25 typedef std::multiset<int> M; 26 { 27 V ar1[] = 28 { 29 }; 30 V ar2[] = 31 { 32 }; 33 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 34 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 35 M m1_save = m1; 36 M m2_save = m2; 37 m1.swap(m2); 38 assert(m1 == m2_save); 39 assert(m2 == m1_save); 40 } 41 { 42 V ar1[] = 43 { 44 }; 45 V ar2[] = 46 { 47 5, 48 6, 49 7, 50 8, 51 9, 52 10, 53 11, 54 12 55 }; 56 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 57 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 58 M m1_save = m1; 59 M m2_save = m2; 60 m1.swap(m2); 61 assert(m1 == m2_save); 62 assert(m2 == m1_save); 63 } 64 { 65 V ar1[] = 66 { 67 1, 68 2, 69 3, 70 4 71 }; 72 V ar2[] = 73 { 74 }; 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 V ar1[] = 85 { 86 1, 87 2, 88 3, 89 4 90 }; 91 V ar2[] = 92 { 93 5, 94 6, 95 7, 96 8, 97 9, 98 10, 99 11, 100 12 101 }; 102 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 103 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 104 M m1_save = m1; 105 M m2_save = m2; 106 m1.swap(m2); 107 assert(m1 == m2_save); 108 assert(m2 == m1_save); 109 } 110 } 111 #if __cplusplus >= 201103L 112 { 113 typedef int V; 114 typedef std::multiset<int, std::less<int>, min_allocator<int>> M; 115 { 116 V ar1[] = 117 { 118 }; 119 V ar2[] = 120 { 121 }; 122 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 123 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 124 M m1_save = m1; 125 M m2_save = m2; 126 m1.swap(m2); 127 assert(m1 == m2_save); 128 assert(m2 == m1_save); 129 } 130 { 131 V ar1[] = 132 { 133 }; 134 V ar2[] = 135 { 136 5, 137 6, 138 7, 139 8, 140 9, 141 10, 142 11, 143 12 144 }; 145 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 146 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 147 M m1_save = m1; 148 M m2_save = m2; 149 m1.swap(m2); 150 assert(m1 == m2_save); 151 assert(m2 == m1_save); 152 } 153 { 154 V ar1[] = 155 { 156 1, 157 2, 158 3, 159 4 160 }; 161 V ar2[] = 162 { 163 }; 164 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 165 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 166 M m1_save = m1; 167 M m2_save = m2; 168 m1.swap(m2); 169 assert(m1 == m2_save); 170 assert(m2 == m1_save); 171 } 172 { 173 V ar1[] = 174 { 175 1, 176 2, 177 3, 178 4 179 }; 180 V ar2[] = 181 { 182 5, 183 6, 184 7, 185 8, 186 9, 187 10, 188 11, 189 12 190 }; 191 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 192 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 193 M m1_save = m1; 194 M m2_save = m2; 195 m1.swap(m2); 196 assert(m1 == m2_save); 197 assert(m2 == m1_save); 198 } 199 } 200 #endif 201 } 202