brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · f2caf36 Raw
50 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// <map>12 13// class multimap14 15// template<typename K>16//         pair<iterator,iterator>             equal_range(const K& x); // C++1417// template<typename K>18//         pair<const_iterator,const_iterator> equal_range(const K& x) const;19//         // C++1420 21#include <cassert>22#include <map>23#include <utility>24 25struct Comp {26  using is_transparent = void;27 28  bool operator()(const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) const { return lhs < rhs; }29 30  bool operator()(const std::pair<int, int>& lhs, int rhs) const { return lhs.first < rhs; }31 32  bool operator()(int lhs, const std::pair<int, int>& rhs) const { return lhs < rhs.first; }33};34 35int main(int, char**) {36  std::multimap<std::pair<int, int>, int, Comp> s{{{2, 1}, 1}, {{1, 1}, 2}, {{1, 1}, 3}, {{1, 1}, 4}, {{2, 2}, 5}};37 38  auto er   = s.equal_range(1);39  long nels = 0;40 41  for (auto it = er.first; it != er.second; it++) {42    assert(it->first.first == 1);43    nels++;44  }45 46  assert(nels == 3);47 48  return 0;49}50