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 | // bool contains(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 | using M = std::flat_multimap<Key, Value, std::less<>, KeyContainer, ValueContainer>; |
33 | M m = {{1, 1}, {2, 2}, {2, 3}, {4, 4}, {5, 5}, {8, 1}, {8, 2}, {8, 8}}; |
34 | assert(!m.contains(0)); |
35 | assert(m.contains(1)); |
36 | assert(m.contains(2)); |
37 | assert(!m.contains(3)); |
38 | assert(m.contains(4)); |
39 | assert(m.contains(5)); |
40 | assert(!m.contains(6)); |
41 | assert(!m.contains(7)); |
42 | assert(std::as_const(m).contains(8)); |
43 | assert(!std::as_const(m).contains(9)); |
44 | m.clear(); |
45 | assert(!m.contains(1)); |
46 | } |
47 | { |
48 | using M = std::flat_multimap<Key, Value, std::greater<int>, KeyContainer, ValueContainer>; |
49 | M m = {{1, 0}, {2, 0}, {4, 0}, {2, 1}, {5, 1}, {5, 2}, {5, 0}, {8, 0}}; |
50 | assert(!m.contains(0)); |
51 | assert(m.contains(1)); |
52 | assert(m.contains(2)); |
53 | assert(!m.contains(3)); |
54 | assert(m.contains(4)); |
55 | assert(m.contains(5)); |
56 | assert(!m.contains(6)); |
57 | assert(!m.contains(7)); |
58 | assert(std::as_const(m).contains(8)); |
59 | assert(!std::as_const(m).contains(9)); |
60 | m.clear(); |
61 | assert(!m.contains(1)); |
62 | } |
63 | } |
64 | |
65 | int main(int, char**) { |
66 | test<std::vector<int>, std::vector<int>>(); |
67 | test<std::deque<int>, std::vector<int>>(); |
68 | test<MinSequenceContainer<int>, MinSequenceContainer<int>>(); |
69 | test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>(); |
70 | |
71 | return 0; |
72 | } |
73 | |