count_transparent.pass.cpp (1214B)
1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11 11 12 // <map> 13 14 // class multimap 15 16 // template<typename K> 17 // size_type count(const K& x) const; // C++14 18 19 #include <cassert> 20 #include <map> 21 #include <utility> 22 23 #include "min_allocator.h" 24 #include "private_constructor.hpp" 25 #include "test_macros.h" 26 27 struct Comp { 28 using is_transparent = void; 29 30 bool operator()(const std::pair<int, int> &lhs, 31 const std::pair<int, int> &rhs) const { 32 return lhs < rhs; 33 } 34 35 bool operator()(const std::pair<int, int> &lhs, int rhs) const { 36 return lhs.first < rhs; 37 } 38 39 bool operator()(int lhs, const std::pair<int, int> &rhs) const { 40 return lhs < rhs.first; 41 } 42 }; 43 44 int main() { 45 std::multimap<std::pair<int, int>, int, Comp> s{ 46 {{2, 1}, 1}, {{1, 1}, 2}, {{1, 1}, 3}, {{1, 1}, 4}, {{2, 2}, 5}}; 47 48 auto cnt = s.count(1); 49 assert(cnt == 3); 50 }