Debian Codegraph @

libcxx/test/std/containers/unord/unord.map/contains.pass.cpp

raw
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
10
11 #include <cassert>
12 #include <unordered_map>
13
14 // <unordered_map>
15
16 // bool contains(const key_type& x) const;
17
18 template <typename T, typename P, typename B, typename... Pairs>
19 void test(B bad, Pairs... args) {
20 T map;
21 P pairs[] = {args...};
22
23 for (auto& p : pairs)
24 map.insert(p);
25 for (auto& p : pairs)
26 assert(map.contains(p.first));
27
28 assert(!map.contains(bad));
29 }
30
31 struct E {
32 int a = 1;
33 double b = 1;
34 char c = 1;
35 };
36
37 int main(int, char**) {
38 {
39 test<std::unordered_map<char, int>, std::pair<char, int> >(
40 'e', std::make_pair('a', 10), std::make_pair('b', 11), std::make_pair('c', 12), std::make_pair('d', 13));
41
42 test<std::unordered_map<char, char>, std::pair<char, char> >(
43 'e', std::make_pair('a', 'a'), std::make_pair('b', 'a'), std::make_pair('c', 'a'), std::make_pair('d', 'b'));
44
45 test<std::unordered_map<int, E>, std::pair<int, E> >(
46 -1, std::make_pair(1, E{}), std::make_pair(2, E{}), std::make_pair(3, E{}), std::make_pair(4, E{}));
47 }
48 {
49 test<std::unordered_multimap<char, int>, std::pair<char, int> >(
50 'e', std::make_pair('a', 10), std::make_pair('b', 11), std::make_pair('c', 12), std::make_pair('d', 13));
51
52 test<std::unordered_multimap<char, char>, std::pair<char, char> >(
53 'e', std::make_pair('a', 'a'), std::make_pair('b', 'a'), std::make_pair('c', 'a'), std::make_pair('d', 'b'));
54
55 test<std::unordered_multimap<int, E>, std::pair<int, E> >(
56 -1, std::make_pair(1, E{}), std::make_pair(2, E{}), std::make_pair(3, E{}), std::make_pair(4, E{}));
57 }
58
59 return 0;
60 }