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 // void insert(InputIterator first, InputIterator last); 15 16 #include <map> 17 #include <cassert> 18 19 #include "test_iterators.h" 20 #include "min_allocator.h" 21 22 int main(int, char**) 23 { 24 { 25 typedef std::multimap<int, double> M; 26 typedef std::pair<int, double> P; 27 P ar[] = 28 { 29 P(1, 1), 30 P(1, 1.5), 31 P(1, 2), 32 P(2, 1), 33 P(2, 1.5), 34 P(2, 2), 35 P(3, 1), 36 P(3, 1.5), 37 P(3, 2), 38 }; 39 M m; 40 m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0]))); 41 assert(m.size() == 9); 42 assert(m.begin()->first == 1); 43 assert(m.begin()->second == 1); 44 assert(next(m.begin())->first == 1); 45 assert(next(m.begin())->second == 1.5); 46 assert(next(m.begin(), 2)->first == 1); 47 assert(next(m.begin(), 2)->second == 2); 48 assert(next(m.begin(), 3)->first == 2); 49 assert(next(m.begin(), 3)->second == 1); 50 assert(next(m.begin(), 4)->first == 2); 51 assert(next(m.begin(), 4)->second == 1.5); 52 assert(next(m.begin(), 5)->first == 2); 53 assert(next(m.begin(), 5)->second == 2); 54 assert(next(m.begin(), 6)->first == 3); 55 assert(next(m.begin(), 6)->second == 1); 56 assert(next(m.begin(), 7)->first == 3); 57 assert(next(m.begin(), 7)->second == 1.5); 58 assert(next(m.begin(), 8)->first == 3); 59 assert(next(m.begin(), 8)->second == 2); 60 } 61 #if TEST_STD_VER >= 11 62 { 63 typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 64 typedef std::pair<int, double> P; 65 P ar[] = 66 { 67 P(1, 1), 68 P(1, 1.5), 69 P(1, 2), 70 P(2, 1), 71 P(2, 1.5), 72 P(2, 2), 73 P(3, 1), 74 P(3, 1.5), 75 P(3, 2), 76 }; 77 M m; 78 m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0]))); 79 assert(m.size() == 9); 80 assert(m.begin()->first == 1); 81 assert(m.begin()->second == 1); 82 assert(next(m.begin())->first == 1); 83 assert(next(m.begin())->second == 1.5); 84 assert(next(m.begin(), 2)->first == 1); 85 assert(next(m.begin(), 2)->second == 2); 86 assert(next(m.begin(), 3)->first == 2); 87 assert(next(m.begin(), 3)->second == 1); 88 assert(next(m.begin(), 4)->first == 2); 89 assert(next(m.begin(), 4)->second == 1.5); 90 assert(next(m.begin(), 5)->first == 2); 91 assert(next(m.begin(), 5)->second == 2); 92 assert(next(m.begin(), 6)->first == 3); 93 assert(next(m.begin(), 6)->second == 1); 94 assert(next(m.begin(), 7)->first == 3); 95 assert(next(m.begin(), 7)->second == 1.5); 96 assert(next(m.begin(), 8)->first == 3); 97 assert(next(m.begin(), 8)->second == 2); 98 } 99 #endif 100 101 return 0; 102 } 103