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 // iterator begin(); 15 // const_iterator begin() const; 16 // iterator end(); 17 // const_iterator end() const; 18 // 19 // reverse_iterator rbegin(); 20 // const_reverse_iterator rbegin() const; 21 // reverse_iterator rend(); 22 // const_reverse_iterator rend() const; 23 // 24 // const_iterator cbegin() const; 25 // const_iterator cend() const; 26 // const_reverse_iterator crbegin() const; 27 // const_reverse_iterator crend() const; 28 29 #include <map> 30 #include <cassert> 31 32 #include "../../../min_allocator.h" 33 34 int main() 35 { 36 { 37 typedef std::pair<const int, double> V; 38 V ar[] = 39 { 40 V(1, 1), 41 V(1, 1.5), 42 V(1, 2), 43 V(2, 1), 44 V(2, 1.5), 45 V(2, 2), 46 V(3, 1), 47 V(3, 1.5), 48 V(3, 2), 49 V(4, 1), 50 V(4, 1.5), 51 V(4, 2), 52 V(5, 1), 53 V(5, 1.5), 54 V(5, 2), 55 V(6, 1), 56 V(6, 1.5), 57 V(6, 2), 58 V(7, 1), 59 V(7, 1.5), 60 V(7, 2), 61 V(8, 1), 62 V(8, 1.5), 63 V(8, 2) 64 }; 65 std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 66 assert(std::distance(m.begin(), m.end()) == m.size()); 67 assert(std::distance(m.rbegin(), m.rend()) == m.size()); 68 std::map<int, double>::iterator i; 69 i = m.begin(); 70 std::map<int, double>::const_iterator k = i; 71 assert(i == k); 72 for (int j = 1; j <= m.size(); ++j, ++i) 73 { 74 assert(i->first == j); 75 assert(i->second == 1); 76 i->second = 2.5; 77 assert(i->second == 2.5); 78 } 79 } 80 { 81 typedef std::pair<const int, double> V; 82 V ar[] = 83 { 84 V(1, 1), 85 V(1, 1.5), 86 V(1, 2), 87 V(2, 1), 88 V(2, 1.5), 89 V(2, 2), 90 V(3, 1), 91 V(3, 1.5), 92 V(3, 2), 93 V(4, 1), 94 V(4, 1.5), 95 V(4, 2), 96 V(5, 1), 97 V(5, 1.5), 98 V(5, 2), 99 V(6, 1), 100 V(6, 1.5), 101 V(6, 2), 102 V(7, 1), 103 V(7, 1.5), 104 V(7, 2), 105 V(8, 1), 106 V(8, 1.5), 107 V(8, 2) 108 }; 109 const std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 110 assert(std::distance(m.begin(), m.end()) == m.size()); 111 assert(std::distance(m.cbegin(), m.cend()) == m.size()); 112 assert(std::distance(m.rbegin(), m.rend()) == m.size()); 113 assert(std::distance(m.crbegin(), m.crend()) == m.size()); 114 std::map<int, double>::const_iterator i; 115 i = m.begin(); 116 for (int j = 1; j <= m.size(); ++j, ++i) 117 { 118 assert(i->first == j); 119 assert(i->second == 1); 120 } 121 } 122 #if __cplusplus >= 201103L 123 { 124 typedef std::pair<const int, double> V; 125 V ar[] = 126 { 127 V(1, 1), 128 V(1, 1.5), 129 V(1, 2), 130 V(2, 1), 131 V(2, 1.5), 132 V(2, 2), 133 V(3, 1), 134 V(3, 1.5), 135 V(3, 2), 136 V(4, 1), 137 V(4, 1.5), 138 V(4, 2), 139 V(5, 1), 140 V(5, 1.5), 141 V(5, 2), 142 V(6, 1), 143 V(6, 1.5), 144 V(6, 2), 145 V(7, 1), 146 V(7, 1.5), 147 V(7, 2), 148 V(8, 1), 149 V(8, 1.5), 150 V(8, 2) 151 }; 152 std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 153 assert(std::distance(m.begin(), m.end()) == m.size()); 154 assert(std::distance(m.rbegin(), m.rend()) == m.size()); 155 std::map<int, double, std::less<int>, min_allocator<V>>::iterator i; 156 i = m.begin(); 157 std::map<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i; 158 assert(i == k); 159 for (int j = 1; j <= m.size(); ++j, ++i) 160 { 161 assert(i->first == j); 162 assert(i->second == 1); 163 i->second = 2.5; 164 assert(i->second == 2.5); 165 } 166 } 167 { 168 typedef std::pair<const int, double> V; 169 V ar[] = 170 { 171 V(1, 1), 172 V(1, 1.5), 173 V(1, 2), 174 V(2, 1), 175 V(2, 1.5), 176 V(2, 2), 177 V(3, 1), 178 V(3, 1.5), 179 V(3, 2), 180 V(4, 1), 181 V(4, 1.5), 182 V(4, 2), 183 V(5, 1), 184 V(5, 1.5), 185 V(5, 2), 186 V(6, 1), 187 V(6, 1.5), 188 V(6, 2), 189 V(7, 1), 190 V(7, 1.5), 191 V(7, 2), 192 V(8, 1), 193 V(8, 1.5), 194 V(8, 2) 195 }; 196 const std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 197 assert(std::distance(m.begin(), m.end()) == m.size()); 198 assert(std::distance(m.cbegin(), m.cend()) == m.size()); 199 assert(std::distance(m.rbegin(), m.rend()) == m.size()); 200 assert(std::distance(m.crbegin(), m.crend()) == m.size()); 201 std::map<int, double, std::less<int>, min_allocator<V>>::const_iterator i; 202 i = m.begin(); 203 for (int j = 1; j <= m.size(); ++j, ++i) 204 { 205 assert(i->first == j); 206 assert(i->second == 1); 207 } 208 } 209 #endif 210 } 211