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 map 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::map<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() == 3); 42 assert(m.begin()->first == 1); 43 assert(m.begin()->second == 1); 44 assert(next(m.begin())->first == 2); 45 assert(next(m.begin())->second == 1); 46 assert(next(m.begin(), 2)->first == 3); 47 assert(next(m.begin(), 2)->second == 1); 48 } 49 #if TEST_STD_VER >= 11 50 { 51 typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; 52 typedef std::pair<int, double> P; 53 P ar[] = 54 { 55 P(1, 1), 56 P(1, 1.5), 57 P(1, 2), 58 P(2, 1), 59 P(2, 1.5), 60 P(2, 2), 61 P(3, 1), 62 P(3, 1.5), 63 P(3, 2), 64 }; 65 M m; 66 m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0]))); 67 assert(m.size() == 3); 68 assert(m.begin()->first == 1); 69 assert(m.begin()->second == 1); 70 assert(next(m.begin())->first == 2); 71 assert(next(m.begin())->second == 1); 72 assert(next(m.begin(), 2)->first == 3); 73 assert(next(m.begin(), 2)->second == 1); 74 } 75 #endif 76 77 return 0; 78 } 79