llvm-project
46 строк · 1.1 Кб
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
10
11// <set>
12
13// class set
14
15// template<typename K>
16// size_type count(const K& x) const; // C++14
17
18#include <cassert>
19#include <set>
20#include <utility>
21
22struct Comp {
23using is_transparent = void;
24
25bool operator()(const std::pair<int, int> &lhs,
26const std::pair<int, int> &rhs) const {
27return lhs < rhs;
28}
29
30bool operator()(const std::pair<int, int> &lhs, int rhs) const {
31return lhs.first < rhs;
32}
33
34bool operator()(int lhs, const std::pair<int, int> &rhs) const {
35return lhs < rhs.first;
36}
37};
38
39int main(int, char**) {
40std::set<std::pair<int, int>, Comp> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}};
41
42auto cnt = s.count(1);
43assert(cnt == 3);
44
45return 0;
46}
47