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 // mapped_type& operator[](const key_type& k); 15 16 #include <map> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 #include "private_constructor.hpp" 21 22 int main() 23 { 24 { 25 typedef std::pair<const int, double> V; 26 V ar[] = 27 { 28 V(1, 1.5), 29 V(2, 2.5), 30 V(3, 3.5), 31 V(4, 4.5), 32 V(5, 5.5), 33 V(7, 7.5), 34 V(8, 8.5), 35 }; 36 std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 37 assert(m.size() == 7); 38 assert(m[1] == 1.5); 39 assert(m.size() == 7); 40 m[1] = -1.5; 41 assert(m[1] == -1.5); 42 assert(m.size() == 7); 43 assert(m[6] == 0); 44 assert(m.size() == 8); 45 m[6] = 6.5; 46 assert(m[6] == 6.5); 47 assert(m.size() == 8); 48 } 49 #if __cplusplus >= 201103L 50 { 51 typedef std::pair<const int, double> V; 52 V ar[] = 53 { 54 V(1, 1.5), 55 V(2, 2.5), 56 V(3, 3.5), 57 V(4, 4.5), 58 V(5, 5.5), 59 V(7, 7.5), 60 V(8, 8.5), 61 }; 62 std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 63 assert(m.size() == 7); 64 assert(m[1] == 1.5); 65 assert(m.size() == 7); 66 const int i = 1; 67 m[i] = -1.5; 68 assert(m[1] == -1.5); 69 assert(m.size() == 7); 70 assert(m[6] == 0); 71 assert(m.size() == 8); 72 m[6] = 6.5; 73 assert(m[6] == 6.5); 74 assert(m.size() == 8); 75 } 76 #endif 77 #if _LIBCPP_STD_VER > 11 78 { 79 typedef std::pair<const int, double> V; 80 V ar[] = 81 { 82 V(1, 1.5), 83 V(2, 2.5), 84 V(3, 3.5), 85 V(4, 4.5), 86 V(5, 5.5), 87 V(7, 7.5), 88 V(8, 8.5), 89 }; 90 std::map<int, double, std::less<>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 91 92 assert(m.size() == 7); 93 assert(m[1] == 1.5); 94 assert(m.size() == 7); 95 m[1] = -1.5; 96 assert(m[1] == -1.5); 97 assert(m.size() == 7); 98 assert(m[6] == 0); 99 assert(m.size() == 8); 100 m[6] = 6.5; 101 assert(m[6] == 6.5); 102 assert(m.size() == 8); 103 } 104 #endif 105 } 106