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 // UNSUPPORTED: c++98, c++03 11 12 // <map> 13 14 // class map 15 16 // mapped_type& operator[](key_type&& k); 17 18 #include <map> 19 #include <cassert> 20 21 #include "test_macros.h" 22 #include "count_new.hpp" 23 #include "MoveOnly.h" 24 #include "min_allocator.h" 25 #include "container_test_types.h" 26 main()27int main() 28 { 29 { 30 std::map<MoveOnly, double> m; 31 assert(m.size() == 0); 32 assert(m[1] == 0.0); 33 assert(m.size() == 1); 34 m[1] = -1.5; 35 assert(m[1] == -1.5); 36 assert(m.size() == 1); 37 assert(m[6] == 0); 38 assert(m.size() == 2); 39 m[6] = 6.5; 40 assert(m[6] == 6.5); 41 assert(m.size() == 2); 42 } 43 { 44 typedef std::pair<const MoveOnly, double> V; 45 std::map<MoveOnly, double, std::less<MoveOnly>, min_allocator<V>> m; 46 assert(m.size() == 0); 47 assert(m[1] == 0.0); 48 assert(m.size() == 1); 49 m[1] = -1.5; 50 assert(m[1] == -1.5); 51 assert(m.size() == 1); 52 assert(m[6] == 0); 53 assert(m.size() == 2); 54 m[6] = 6.5; 55 assert(m[6] == 6.5); 56 assert(m.size() == 2); 57 } 58 { 59 // Use "container_test_types.h" to check what arguments get passed 60 // to the allocator for operator[] 61 using Container = TCT::map<>; 62 using Key = Container::key_type; 63 using MappedType = Container::mapped_type; 64 using ValueTp = Container::value_type; 65 ConstructController* cc = getConstructController(); 66 cc->reset(); 67 { 68 Container c; 69 Key k(1); 70 cc->expect<std::piecewise_construct_t const&, std::tuple<Key &&>&&, std::tuple<>&&>(); 71 MappedType& mref = c[std::move(k)]; 72 assert(!cc->unchecked()); 73 { 74 Key k2(1); 75 DisableAllocationGuard g; 76 MappedType& mref2 = c[std::move(k2)]; 77 assert(&mref == &mref2); 78 } 79 } 80 } 81 } 82