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
18template <typename T, typename P, typename B, typename... Pairs>
19void 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
31struct E {
32 int a = 1;
33 double b = 1;
34 char c = 1;
35};
36
37int main(int, char**) {
38 {
39 test<std::unordered_map<char, int>, std::pair<char, int> >(
40 bad: 'e', args: std::make_pair(x: 'a', y: 10), args: std::make_pair(x: 'b', y: 11), args: std::make_pair(x: 'c', y: 12), args: std::make_pair(x: 'd', y: 13));
41
42 test<std::unordered_map<char, char>, std::pair<char, char> >(
43 bad: 'e', args: std::make_pair(x: 'a', y: 'a'), args: std::make_pair(x: 'b', y: 'a'), args: std::make_pair(x: 'c', y: 'a'), args: std::make_pair(x: 'd', y: 'b'));
44
45 test<std::unordered_map<int, E>, std::pair<int, E> >(
46 bad: -1, args: std::make_pair(x: 1, y: E{}), args: std::make_pair(x: 2, y: E{}), args: std::make_pair(x: 3, y: E{}), args: std::make_pair(x: 4, y: E{}));
47 }
48 {
49 test<std::unordered_multimap<char, int>, std::pair<char, int> >(
50 bad: 'e', args: std::make_pair(x: 'a', y: 10), args: std::make_pair(x: 'b', y: 11), args: std::make_pair(x: 'c', y: 12), args: std::make_pair(x: 'd', y: 13));
51
52 test<std::unordered_multimap<char, char>, std::pair<char, char> >(
53 bad: 'e', args: std::make_pair(x: 'a', y: 'a'), args: std::make_pair(x: 'b', y: 'a'), 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{}), args: std::make_pair(x: 3, y: E{}), args: std::make_pair(x: 4, y: E{}));
57 }
58
59 return 0;
60}
61

source code of libcxx/test/std/containers/unord/unord.map/contains.pass.cpp