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) map.insert(p); |
24 | for (auto& p : pairs) assert(map.contains(p.first)); |
25 | |
26 | assert(!map.contains(bad)); |
27 | } |
28 | |
29 | struct E { int a = 1; double b = 1; char c = 1; }; |
30 | |
31 | int main(int, char**) |
32 | { |
33 | { |
34 | test<std::unordered_map<char, int>, std::pair<char, int> >( |
35 | bad: 'e', args: std::make_pair(x: 'a', y: 10), args: std::make_pair(x: 'b', y: 11), |
36 | args: std::make_pair(x: 'c', y: 12), args: std::make_pair(x: 'd', y: 13)); |
37 | |
38 | test<std::unordered_map<char, char>, std::pair<char, char> >( |
39 | bad: 'e', args: std::make_pair(x: 'a', y: 'a'), args: std::make_pair(x: 'b', y: 'a'), |
40 | args: std::make_pair(x: 'c', y: 'a'), args: std::make_pair(x: 'd', y: 'b')); |
41 | |
42 | test<std::unordered_map<int, E>, std::pair<int, E> >( |
43 | bad: -1, args: std::make_pair(x: 1, y: E{}), args: std::make_pair(x: 2, y: E{}), |
44 | args: std::make_pair(x: 3, y: E{}), args: std::make_pair(x: 4, y: E{})); |
45 | } |
46 | { |
47 | test<std::unordered_multimap<char, int>, std::pair<char, int> >( |
48 | bad: 'e', args: std::make_pair(x: 'a', y: 10), args: std::make_pair(x: 'b', y: 11), |
49 | args: std::make_pair(x: 'c', y: 12), args: std::make_pair(x: 'd', y: 13)); |
50 | |
51 | test<std::unordered_multimap<char, char>, std::pair<char, char> >( |
52 | bad: 'e', args: std::make_pair(x: 'a', y: 'a'), args: std::make_pair(x: 'b', y: 'a'), |
53 | args: std::make_pair(x: 'c', y: 'a'), args: std::make_pair(x: 'd', y: 'b')); |
54 | |
55 | test<std::unordered_multimap<int, E>, std::pair<int, E> >( |
56 | bad: -1, args: std::make_pair(x: 1, y: E{}), args: std::make_pair(x: 2, y: E{}), |
57 | args: std::make_pair(x: 3, y: E{}), args: std::make_pair(x: 4, y: E{})); |
58 | } |
59 | |
60 | return 0; |
61 | } |
62 | |