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