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 multimap 13 14 // template <class... Args> 15 // iterator emplace(Args&&... args); 16 17 #include <map> 18 #include <cassert> 19 20 #include "../../../Emplaceable.h" 21 #include "DefaultOnly.h" 22 #include "min_allocator.h" 23 24 int main() 25 { 26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 27 { 28 typedef std::multimap<int, DefaultOnly> M; 29 typedef M::iterator R; 30 M m; 31 assert(DefaultOnly::count == 0); 32 R r = m.emplace(); 33 assert(r == m.begin()); 34 assert(m.size() == 1); 35 assert(m.begin()->first == 0); 36 assert(m.begin()->second == DefaultOnly()); 37 assert(DefaultOnly::count == 1); 38 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 39 std::forward_as_tuple()); 40 assert(r == next(m.begin())); 41 assert(m.size() == 2); 42 assert(next(m.begin())->first == 1); 43 assert(next(m.begin())->second == DefaultOnly()); 44 assert(DefaultOnly::count == 2); 45 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 46 std::forward_as_tuple()); 47 assert(r == next(m.begin(), 2)); 48 assert(m.size() == 3); 49 assert(next(m.begin(), 2)->first == 1); 50 assert(next(m.begin(), 2)->second == DefaultOnly()); 51 assert(DefaultOnly::count == 3); 52 } 53 assert(DefaultOnly::count == 0); 54 { 55 typedef std::multimap<int, Emplaceable> M; 56 typedef M::iterator R; 57 M m; 58 R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), 59 std::forward_as_tuple()); 60 assert(r == m.begin()); 61 assert(m.size() == 1); 62 assert(m.begin()->first == 2); 63 assert(m.begin()->second == Emplaceable()); 64 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 65 std::forward_as_tuple(2, 3.5)); 66 assert(r == m.begin()); 67 assert(m.size() == 2); 68 assert(m.begin()->first == 1); 69 assert(m.begin()->second == Emplaceable(2, 3.5)); 70 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 71 std::forward_as_tuple(3, 3.5)); 72 assert(r == next(m.begin())); 73 assert(m.size() == 3); 74 assert(r->first == 1); 75 assert(r->second == Emplaceable(3, 3.5)); 76 } 77 { 78 typedef std::multimap<int, double> M; 79 typedef M::iterator R; 80 M m; 81 R r = m.emplace(M::value_type(2, 3.5)); 82 assert(r == m.begin()); 83 assert(m.size() == 1); 84 assert(m.begin()->first == 2); 85 assert(m.begin()->second == 3.5); 86 } 87 #if __cplusplus >= 201103L 88 { 89 typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; 90 typedef M::iterator R; 91 M m; 92 assert(DefaultOnly::count == 0); 93 R r = m.emplace(); 94 assert(r == m.begin()); 95 assert(m.size() == 1); 96 assert(m.begin()->first == 0); 97 assert(m.begin()->second == DefaultOnly()); 98 assert(DefaultOnly::count == 1); 99 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 100 std::forward_as_tuple()); 101 assert(r == next(m.begin())); 102 assert(m.size() == 2); 103 assert(next(m.begin())->first == 1); 104 assert(next(m.begin())->second == DefaultOnly()); 105 assert(DefaultOnly::count == 2); 106 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 107 std::forward_as_tuple()); 108 assert(r == next(m.begin(), 2)); 109 assert(m.size() == 3); 110 assert(next(m.begin(), 2)->first == 1); 111 assert(next(m.begin(), 2)->second == DefaultOnly()); 112 assert(DefaultOnly::count == 3); 113 } 114 assert(DefaultOnly::count == 0); 115 { 116 typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; 117 typedef M::iterator R; 118 M m; 119 R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), 120 std::forward_as_tuple()); 121 assert(r == m.begin()); 122 assert(m.size() == 1); 123 assert(m.begin()->first == 2); 124 assert(m.begin()->second == Emplaceable()); 125 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 126 std::forward_as_tuple(2, 3.5)); 127 assert(r == m.begin()); 128 assert(m.size() == 2); 129 assert(m.begin()->first == 1); 130 assert(m.begin()->second == Emplaceable(2, 3.5)); 131 r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), 132 std::forward_as_tuple(3, 3.5)); 133 assert(r == next(m.begin())); 134 assert(m.size() == 3); 135 assert(r->first == 1); 136 assert(r->second == Emplaceable(3, 3.5)); 137 } 138 { 139 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 140 typedef M::iterator R; 141 M m; 142 R r = m.emplace(M::value_type(2, 3.5)); 143 assert(r == m.begin()); 144 assert(m.size() == 1); 145 assert(m.begin()->first == 2); 146 assert(m.begin()->second == 3.5); 147 } 148 #endif 149 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 150 } 151