count_transparent.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // UNSUPPORTED: c++98, c++03, c++11
  9. // <map>
  10. // class multimap
  11. // template<typename K>
  12. // size_type count(const K& x) const; // C++14
  13. #include <cassert>
  14. #include <map>
  15. #include <utility>
  16. #include "min_allocator.h"
  17. #include "private_constructor.h"
  18. #include "test_macros.h"
  19. struct Comp {
  20. using is_transparent = void;
  21. bool operator()(const std::pair<int, int> &lhs,
  22. const std::pair<int, int> &rhs) const {
  23. return lhs < rhs;
  24. }
  25. bool operator()(const std::pair<int, int> &lhs, int rhs) const {
  26. return lhs.first < rhs;
  27. }
  28. bool operator()(int lhs, const std::pair<int, int> &rhs) const {
  29. return lhs < rhs.first;
  30. }
  31. };
  32. int main(int, char**) {
  33. std::multimap<std::pair<int, int>, int, Comp> s{
  34. {{2, 1}, 1}, {{1, 1}, 2}, {{1, 1}, 3}, {{1, 1}, 4}, {{2, 2}, 5}};
  35. auto cnt = s.count(1);
  36. assert(cnt == 3);
  37. return 0;
  38. }