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 // <map> 11 12 // class map 13 14 // void swap(map& m); 15 16 #include <map> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 21 int main() 22 { 23 typedef std::pair<const int, double> V; 24 { 25 typedef std::map<int, double> M; 26 { 27 M m1; 28 M m2; 29 M m1_save = m1; 30 M m2_save = m2; 31 m1.swap(m2); 32 assert(m1 == m2_save); 33 assert(m2 == m1_save); 34 } 35 { 36 V ar2[] = 37 { 38 V(5, 5), 39 V(6, 6), 40 V(7, 7), 41 V(8, 8), 42 V(9, 9), 43 V(10, 10), 44 V(11, 11), 45 V(12, 12) 46 }; 47 M m1; 48 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 49 M m1_save = m1; 50 M m2_save = m2; 51 m1.swap(m2); 52 assert(m1 == m2_save); 53 assert(m2 == m1_save); 54 } 55 { 56 V ar1[] = 57 { 58 V(1, 1), 59 V(2, 2), 60 V(3, 3), 61 V(4, 4) 62 }; 63 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 64 M m2; 65 M m1_save = m1; 66 M m2_save = m2; 67 m1.swap(m2); 68 assert(m1 == m2_save); 69 assert(m2 == m1_save); 70 } 71 { 72 V ar1[] = 73 { 74 V(1, 1), 75 V(2, 2), 76 V(3, 3), 77 V(4, 4) 78 }; 79 V ar2[] = 80 { 81 V(5, 5), 82 V(6, 6), 83 V(7, 7), 84 V(8, 8), 85 V(9, 9), 86 V(10, 10), 87 V(11, 11), 88 V(12, 12) 89 }; 90 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 91 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 92 M m1_save = m1; 93 M m2_save = m2; 94 m1.swap(m2); 95 assert(m1 == m2_save); 96 assert(m2 == m1_save); 97 } 98 } 99 #if TEST_STD_VER >= 11 100 { 101 typedef std::map<int, double, std::less<int>, min_allocator<V>> M; 102 { 103 M m1; 104 M m2; 105 M m1_save = m1; 106 M m2_save = m2; 107 m1.swap(m2); 108 assert(m1 == m2_save); 109 assert(m2 == m1_save); 110 } 111 { 112 V ar2[] = 113 { 114 V(5, 5), 115 V(6, 6), 116 V(7, 7), 117 V(8, 8), 118 V(9, 9), 119 V(10, 10), 120 V(11, 11), 121 V(12, 12) 122 }; 123 M m1; 124 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 125 M m1_save = m1; 126 M m2_save = m2; 127 m1.swap(m2); 128 assert(m1 == m2_save); 129 assert(m2 == m1_save); 130 } 131 { 132 V ar1[] = 133 { 134 V(1, 1), 135 V(2, 2), 136 V(3, 3), 137 V(4, 4) 138 }; 139 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 140 M m2; 141 M m1_save = m1; 142 M m2_save = m2; 143 m1.swap(m2); 144 assert(m1 == m2_save); 145 assert(m2 == m1_save); 146 } 147 { 148 V ar1[] = 149 { 150 V(1, 1), 151 V(2, 2), 152 V(3, 3), 153 V(4, 4) 154 }; 155 V ar2[] = 156 { 157 V(5, 5), 158 V(6, 6), 159 V(7, 7), 160 V(8, 8), 161 V(9, 9), 162 V(10, 10), 163 V(11, 11), 164 V(12, 12) 165 }; 166 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); 167 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); 168 M m1_save = m1; 169 M m2_save = m2; 170 m1.swap(m2); 171 assert(m1 == m2_save); 172 assert(m2 == m1_save); 173 } 174 } 175 #endif 176 } 177