1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <map> 10 11 // class multimap 12 13 // template <class InputIterator> 14 // multimap(InputIterator first, InputIterator last); 15 16 #include <map> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "min_allocator.h" 21 22 int main(int, char**) 23 { 24 { 25 typedef std::pair<const int, double> V; 26 V ar[] = 27 { 28 V(1, 1), 29 V(1, 1.5), 30 V(1, 2), 31 V(2, 1), 32 V(2, 1.5), 33 V(2, 2), 34 V(3, 1), 35 V(3, 1.5), 36 V(3, 2), 37 }; 38 std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 39 assert(m.size() == 9); 40 assert(std::distance(m.begin(), m.end()) == 9); 41 assert(*m.begin() == V(1, 1)); 42 assert(*std::next(m.begin()) == V(1, 1.5)); 43 assert(*std::next(m.begin(), 2) == V(1, 2)); 44 assert(*std::next(m.begin(), 3) == V(2, 1)); 45 assert(*std::next(m.begin(), 4) == V(2, 1.5)); 46 assert(*std::next(m.begin(), 5) == V(2, 2)); 47 assert(*std::next(m.begin(), 6) == V(3, 1)); 48 assert(*std::next(m.begin(), 7) == V(3, 1.5)); 49 assert(*std::next(m.begin(), 8) == V(3, 2)); 50 } 51 #if TEST_STD_VER >= 11 52 { 53 typedef std::pair<const int, double> V; 54 V ar[] = 55 { 56 V(1, 1), 57 V(1, 1.5), 58 V(1, 2), 59 V(2, 1), 60 V(2, 1.5), 61 V(2, 2), 62 V(3, 1), 63 V(3, 1.5), 64 V(3, 2), 65 }; 66 std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); 67 assert(m.size() == 9); 68 assert(std::distance(m.begin(), m.end()) == 9); 69 assert(*m.begin() == V(1, 1)); 70 assert(*std::next(m.begin()) == V(1, 1.5)); 71 assert(*std::next(m.begin(), 2) == V(1, 2)); 72 assert(*std::next(m.begin(), 3) == V(2, 1)); 73 assert(*std::next(m.begin(), 4) == V(2, 1.5)); 74 assert(*std::next(m.begin(), 5) == V(2, 2)); 75 assert(*std::next(m.begin(), 6) == V(3, 1)); 76 assert(*std::next(m.begin(), 7) == V(3, 1.5)); 77 assert(*std::next(m.begin(), 8) == V(3, 2)); 78 } 79 #if TEST_STD_VER > 11 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 }; 94 typedef min_allocator<std::pair<const int, double>> A; 95 A a; 96 std::multimap<int, double, std::less<int>, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); 97 assert(m.size() == 9); 98 assert(std::distance(m.begin(), m.end()) == 9); 99 assert(*m.begin() == V(1, 1)); 100 assert(*std::next(m.begin()) == V(1, 1.5)); 101 assert(*std::next(m.begin(), 2) == V(1, 2)); 102 assert(*std::next(m.begin(), 3) == V(2, 1)); 103 assert(*std::next(m.begin(), 4) == V(2, 1.5)); 104 assert(*std::next(m.begin(), 5) == V(2, 2)); 105 assert(*std::next(m.begin(), 6) == V(3, 1)); 106 assert(*std::next(m.begin(), 7) == V(3, 1.5)); 107 assert(*std::next(m.begin(), 8) == V(3, 2)); 108 assert(m.get_allocator() == a); 109 } 110 #endif 111 #endif 112 113 return 0; 114 } 115