llvm-project
48 строк · 1.2 Кб
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 {19using is_transparent = void;20
21bool operator()(const std::pair<int, int>& lhs,22const std::pair<int, int>& rhs) const {23return lhs < rhs;24}25
26bool operator()(const std::pair<int, int>& lhs, int rhs) const {27return lhs.first < rhs;28}29
30bool operator()(int lhs, const std::pair<int, int>& rhs) const {31return lhs < rhs.first;32}33};34
35template <typename Container>36void test() {37Container s{{{2, 1}, 1}, {{1, 2}, 2}, {{1, 3}, 3}, {{1, 4}, 4}, {{2, 2}, 5}};38
39assert(s.contains(1));40assert(!s.contains(-1));41}
42
43int main(int, char**) {44test<std::map<std::pair<int, int>, int, Comp> >();45test<std::multimap<std::pair<int, int>, int, Comp> >();46
47return 0;48}
49