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, c++11, c++14, c++17, c++20 |
10 | |
11 | // <flat_map> |
12 | |
13 | // class flat_multimap |
14 | |
15 | // size_type count(const key_type& x) const; |
16 | |
17 | #include <cassert> |
18 | #include <deque> |
19 | #include <flat_map> |
20 | #include <functional> |
21 | #include <utility> |
22 | |
23 | #include "MinSequenceContainer.h" |
24 | #include "test_macros.h" |
25 | #include "min_allocator.h" |
26 | |
27 | template <class KeyContainer, class ValueContainer> |
28 | void test() { |
29 | using Key = typename KeyContainer::value_type; |
30 | using Value = typename ValueContainer::value_type; |
31 | |
32 | { |
33 | using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>; |
34 | M m = {{1, 1}, {2, 2}, {2, 2}, {4, 4}, {4, 1}, {4, 3}, {4, 4}, {5, 5}, {8, 8}}; |
35 | ASSERT_SAME_TYPE(decltype(m.count(0)), size_t); |
36 | assert(m.count(0) == 0); |
37 | assert(m.count(1) == 1); |
38 | assert(m.count(2) == 2); |
39 | assert(m.count(3) == 0); |
40 | assert(m.count(4) == 4); |
41 | assert(m.count(5) == 1); |
42 | assert(m.count(6) == 0); |
43 | assert(m.count(7) == 0); |
44 | assert(std::as_const(m).count(8) == 1); |
45 | assert(std::as_const(m).count(9) == 0); |
46 | } |
47 | { |
48 | using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>; |
49 | M m = {{1, 0}, {2, 0}, {4, 0}, {1, 0}, {1, 2}, {8, 1}, {5, 0}, {8, 0}}; |
50 | ASSERT_SAME_TYPE(decltype(m.count(0)), size_t); |
51 | assert(m.count(0) == 0); |
52 | assert(m.count(1) == 3); |
53 | assert(m.count(2) == 1); |
54 | assert(m.count(3) == 0); |
55 | assert(m.count(4) == 1); |
56 | assert(m.count(5) == 1); |
57 | assert(m.count(6) == 0); |
58 | assert(m.count(7) == 0); |
59 | assert(std::as_const(m).count(8) == 2); |
60 | assert(std::as_const(m).count(9) == 0); |
61 | } |
62 | } |
63 | |
64 | int main(int, char**) { |
65 | test<std::vector<int>, std::vector<int>>(); |
66 | test<std::deque<int>, std::vector<int>>(); |
67 | test<MinSequenceContainer<int>, MinSequenceContainer<int>>(); |
68 | test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>(); |
69 | |
70 | return 0; |
71 | } |
72 | |