iter_iter_comp_alloc.pass.cpp revision 70342b99e227912742972b754ad86e75c5d7eefb
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 map 13 14// template <class InputIterator> 15// map(InputIterator first, InputIterator last, 16// const key_compare& comp, const allocator_type& a); 17 18#include <map> 19#include <cassert> 20 21#include "../../../test_compare.h" 22#include "../../../test_allocator.h" 23#include "../../../min_allocator.h" 24 25int main() 26{ 27 { 28 typedef std::pair<const int, double> V; 29 V ar[] = 30 { 31 V(1, 1), 32 V(1, 1.5), 33 V(1, 2), 34 V(2, 1), 35 V(2, 1.5), 36 V(2, 2), 37 V(3, 1), 38 V(3, 1.5), 39 V(3, 2), 40 }; 41 typedef test_compare<std::less<int> > C; 42 typedef test_allocator<V> A; 43 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); 44 assert(m.get_allocator() == A(7)); 45 assert(m.key_comp() == C(5)); 46 assert(m.size() == 3); 47 assert(distance(m.begin(), m.end()) == 3); 48 assert(*m.begin() == V(1, 1)); 49 assert(*next(m.begin()) == V(2, 1)); 50 assert(*next(m.begin(), 2) == V(3, 1)); 51 } 52#if __cplusplus >= 201103L 53 { 54 typedef std::pair<const int, double> V; 55 V ar[] = 56 { 57 V(1, 1), 58 V(1, 1.5), 59 V(1, 2), 60 V(2, 1), 61 V(2, 1.5), 62 V(2, 2), 63 V(3, 1), 64 V(3, 1.5), 65 V(3, 2), 66 }; 67 typedef test_compare<std::less<int> > C; 68 typedef min_allocator<V> A; 69 std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); 70 assert(m.get_allocator() == A()); 71 assert(m.key_comp() == C(5)); 72 assert(m.size() == 3); 73 assert(distance(m.begin(), m.end()) == 3); 74 assert(*m.begin() == V(1, 1)); 75 assert(*next(m.begin()) == V(2, 1)); 76 assert(*next(m.begin(), 2) == V(3, 1)); 77 } 78#endif 79} 80