| 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 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <map> |
| 12 | |
| 13 | // class multimap |
| 14 | |
| 15 | // multimap(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); |
| 16 | |
| 17 | #include <map> |
| 18 | #include <cassert> |
| 19 | #include "test_macros.h" |
| 20 | #include "../../../test_compare.h" |
| 21 | #include "test_allocator.h" |
| 22 | #include "min_allocator.h" |
| 23 | |
| 24 | int main(int, char**) { |
| 25 | { |
| 26 | typedef test_less<int> Cmp; |
| 27 | typedef test_allocator<std::pair<const int, double> > A; |
| 28 | typedef std::multimap<int, double, Cmp, A> C; |
| 29 | typedef C::value_type V; |
| 30 | C m({{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, Cmp(4), A(5)); |
| 31 | assert(m.size() == 9); |
| 32 | assert(std::distance(m.begin(), m.end()) == 9); |
| 33 | C::const_iterator i = m.cbegin(); |
| 34 | assert(*i == V(1, 1)); |
| 35 | assert(*++i == V(1, 1.5)); |
| 36 | assert(*++i == V(1, 2)); |
| 37 | assert(*++i == V(2, 1)); |
| 38 | assert(*++i == V(2, 1.5)); |
| 39 | assert(*++i == V(2, 2)); |
| 40 | assert(*++i == V(3, 1)); |
| 41 | assert(*++i == V(3, 1.5)); |
| 42 | assert(*++i == V(3, 2)); |
| 43 | assert(m.key_comp() == Cmp(4)); |
| 44 | assert(m.get_allocator() == A(5)); |
| 45 | } |
| 46 | { |
| 47 | typedef test_less<int> Cmp; |
| 48 | typedef min_allocator<std::pair<const int, double> > A; |
| 49 | typedef std::multimap<int, double, Cmp, A> C; |
| 50 | typedef C::value_type V; |
| 51 | C m({{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, Cmp(4), A()); |
| 52 | assert(m.size() == 9); |
| 53 | assert(std::distance(m.begin(), m.end()) == 9); |
| 54 | C::const_iterator i = m.cbegin(); |
| 55 | assert(*i == V(1, 1)); |
| 56 | assert(*++i == V(1, 1.5)); |
| 57 | assert(*++i == V(1, 2)); |
| 58 | assert(*++i == V(2, 1)); |
| 59 | assert(*++i == V(2, 1.5)); |
| 60 | assert(*++i == V(2, 2)); |
| 61 | assert(*++i == V(3, 1)); |
| 62 | assert(*++i == V(3, 1.5)); |
| 63 | assert(*++i == V(3, 2)); |
| 64 | assert(m.key_comp() == Cmp(4)); |
| 65 | assert(m.get_allocator() == A()); |
| 66 | } |
| 67 | { |
| 68 | typedef test_less<int> C; |
| 69 | typedef std::pair<const int, double> V; |
| 70 | typedef min_allocator<V> A; |
| 71 | typedef std::multimap<int, double, C, A> M; |
| 72 | A a; |
| 73 | M m({{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, a); |
| 74 | |
| 75 | assert(m.size() == 9); |
| 76 | assert(std::distance(m.begin(), m.end()) == 9); |
| 77 | M::const_iterator i = m.cbegin(); |
| 78 | assert(*i == V(1, 1)); |
| 79 | assert(*++i == V(1, 1.5)); |
| 80 | assert(*++i == V(1, 2)); |
| 81 | assert(*++i == V(2, 1)); |
| 82 | assert(*++i == V(2, 1.5)); |
| 83 | assert(*++i == V(2, 2)); |
| 84 | assert(*++i == V(3, 1)); |
| 85 | assert(*++i == V(3, 1.5)); |
| 86 | assert(*++i == V(3, 2)); |
| 87 | assert(m.get_allocator() == a); |
| 88 | } |
| 89 | { |
| 90 | typedef test_less<int> Cmp; |
| 91 | typedef explicit_allocator<std::pair<const int, double> > A; |
| 92 | typedef std::multimap<int, double, Cmp, A> C; |
| 93 | typedef C::value_type V; |
| 94 | C m({{1, 1}, {1, 1.5}, {1, 2}, {2, 1}, {2, 1.5}, {2, 2}, {3, 1}, {3, 1.5}, {3, 2}}, Cmp(4), A{}); |
| 95 | assert(m.size() == 9); |
| 96 | assert(std::distance(m.begin(), m.end()) == 9); |
| 97 | C::const_iterator i = m.cbegin(); |
| 98 | assert(*i == V(1, 1)); |
| 99 | assert(*++i == V(1, 1.5)); |
| 100 | assert(*++i == V(1, 2)); |
| 101 | assert(*++i == V(2, 1)); |
| 102 | assert(*++i == V(2, 1.5)); |
| 103 | assert(*++i == V(2, 2)); |
| 104 | assert(*++i == V(3, 1)); |
| 105 | assert(*++i == V(3, 1.5)); |
| 106 | assert(*++i == V(3, 2)); |
| 107 | assert(m.key_comp() == Cmp(4)); |
| 108 | assert(m.get_allocator() == A{}); |
| 109 | } |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |