brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · a44fcf4 Raw
51 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++1110 11// <set>12 13// class set14 15// template<typename K>16//     pair<iterator,iterator>             equal_range(const K& x);        //17//     C++1418// template<typename K>19//     pair<const_iterator,const_iterator> equal_range(const K& x) const;  //20//     C++1421 22#include <cassert>23#include <set>24#include <utility>25 26struct Comp {27  using is_transparent = void;28 29  bool operator()(const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) const { return lhs < rhs; }30 31  bool operator()(const std::pair<int, int>& lhs, int rhs) const { return lhs.first < rhs; }32 33  bool operator()(int lhs, const std::pair<int, int>& rhs) const { return lhs < rhs.first; }34};35 36int main(int, char**) {37  std::set<std::pair<int, int>, Comp> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}};38 39  auto er   = s.equal_range(1);40  long nels = 0;41 42  for (auto it = er.first; it != er.second; it++) {43    assert(it->first == 1);44    nels++;45  }46 47  assert(nels == 3);48 49  return 0;50}51