| 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 | // <set> |
| 10 | |
| 11 | // class multiset |
| 12 | |
| 13 | // size_type count(const key_type& k) const; |
| 14 | |
| 15 | #include <set> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | #include "private_constructor.h" |
| 21 | |
| 22 | int main(int, char**) { |
| 23 | { |
| 24 | typedef int V; |
| 25 | typedef std::multiset<int> M; |
| 26 | { |
| 27 | typedef M::size_type R; |
| 28 | V ar[] = {5, 5, 5, 5, 7, 7, 7, 9, 9}; |
| 29 | const M m(ar, ar + sizeof(ar) / sizeof(ar[0])); |
| 30 | R r = m.count(x: 4); |
| 31 | assert(r == 0); |
| 32 | r = m.count(x: 5); |
| 33 | assert(r == 4); |
| 34 | r = m.count(x: 6); |
| 35 | assert(r == 0); |
| 36 | r = m.count(x: 7); |
| 37 | assert(r == 3); |
| 38 | r = m.count(x: 8); |
| 39 | assert(r == 0); |
| 40 | r = m.count(x: 9); |
| 41 | assert(r == 2); |
| 42 | r = m.count(x: 10); |
| 43 | assert(r == 0); |
| 44 | } |
| 45 | } |
| 46 | #if TEST_STD_VER >= 11 |
| 47 | { |
| 48 | typedef int V; |
| 49 | typedef std::multiset<int, std::less<int>, min_allocator<int>> M; |
| 50 | { |
| 51 | typedef M::size_type R; |
| 52 | V ar[] = {5, 5, 5, 5, 7, 7, 7, 9, 9}; |
| 53 | const M m(ar, ar + sizeof(ar) / sizeof(ar[0])); |
| 54 | R r = m.count(4); |
| 55 | assert(r == 0); |
| 56 | r = m.count(5); |
| 57 | assert(r == 4); |
| 58 | r = m.count(6); |
| 59 | assert(r == 0); |
| 60 | r = m.count(7); |
| 61 | assert(r == 3); |
| 62 | r = m.count(8); |
| 63 | assert(r == 0); |
| 64 | r = m.count(9); |
| 65 | assert(r == 2); |
| 66 | r = m.count(10); |
| 67 | assert(r == 0); |
| 68 | } |
| 69 | } |
| 70 | #endif |
| 71 | #if TEST_STD_VER > 11 |
| 72 | { |
| 73 | typedef int V; |
| 74 | typedef std::multiset<int, std::less<>> M; |
| 75 | typedef M::size_type R; |
| 76 | V ar[] = {5, 5, 5, 5, 7, 7, 7, 9, 9}; |
| 77 | const M m(ar, ar + sizeof(ar) / sizeof(ar[0])); |
| 78 | R r = m.count(4); |
| 79 | assert(r == 0); |
| 80 | r = m.count(5); |
| 81 | assert(r == 4); |
| 82 | r = m.count(6); |
| 83 | assert(r == 0); |
| 84 | r = m.count(7); |
| 85 | assert(r == 3); |
| 86 | r = m.count(8); |
| 87 | assert(r == 0); |
| 88 | r = m.count(9); |
| 89 | assert(r == 2); |
| 90 | r = m.count(10); |
| 91 | assert(r == 0); |
| 92 | } |
| 93 | |
| 94 | { |
| 95 | typedef PrivateConstructor V; |
| 96 | typedef std::multiset<V, std::less<>> M; |
| 97 | typedef M::size_type R; |
| 98 | |
| 99 | M m; |
| 100 | m.insert(V::make(5)); |
| 101 | m.insert(V::make(5)); |
| 102 | m.insert(V::make(5)); |
| 103 | m.insert(V::make(5)); |
| 104 | m.insert(V::make(7)); |
| 105 | m.insert(V::make(7)); |
| 106 | m.insert(V::make(7)); |
| 107 | m.insert(V::make(9)); |
| 108 | m.insert(V::make(9)); |
| 109 | |
| 110 | R r = m.count(4); |
| 111 | assert(r == 0); |
| 112 | r = m.count(5); |
| 113 | assert(r == 4); |
| 114 | r = m.count(6); |
| 115 | assert(r == 0); |
| 116 | r = m.count(7); |
| 117 | assert(r == 3); |
| 118 | r = m.count(8); |
| 119 | assert(r == 0); |
| 120 | r = m.count(9); |
| 121 | assert(r == 2); |
| 122 | r = m.count(10); |
| 123 | assert(r == 0); |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |