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 <map>
13
14// <map>
15
16// template<class K> bool contains(const K& x) const; // C++20
17
18struct Comp {
19 using is_transparent = void;
20
21 bool operator()(const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) const { return lhs < rhs; }
22
23 bool operator()(const std::pair<int, int>& lhs, int rhs) const { return lhs.first < rhs; }
24
25 bool operator()(int lhs, const std::pair<int, int>& rhs) const { return lhs < rhs.first; }
26};
27
28template <typename Container>
29void test() {
30 Container s{{{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}};
31
32 assert(s.contains(1));
33 assert(!s.contains(-1));
34}
35
36int main(int, char**) {
37 test<std::map<std::pair<int, int>, int, Comp> >();
38 test<std::multimap<std::pair<int, int>, int, Comp> >();
39
40 return 0;
41}
42

source code of libcxx/test/std/containers/associative/map/map.ops/contains_transparent.pass.cpp