count_transparent.pass.cpp (1261B)
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 // <set> 13 14 // class set 15 16 // template<typename K> 17 // iterator lower_bound(const K& x); // C++14 18 // template<typename K> 19 // const_iterator lower_bound(const K& x) const; // C++14 20 21 #include <cassert> 22 #include <set> 23 #include <utility> 24 25 #include "min_allocator.h" 26 #include "private_constructor.hpp" 27 #include "test_macros.h" 28 29 struct Comp { 30 using is_transparent = void; 31 32 bool operator()(const std::pair<int, int> &lhs, 33 const std::pair<int, int> &rhs) const { 34 return lhs < rhs; 35 } 36 37 bool operator()(const std::pair<int, int> &lhs, int rhs) const { 38 return lhs.first < rhs; 39 } 40 41 bool operator()(int lhs, const std::pair<int, int> &rhs) const { 42 return lhs < rhs.first; 43 } 44 }; 45 46 int main() { 47 std::set<std::pair<int, int>, Comp> s{{2, 1}, {1, 2}, {1, 3}, {1, 4}, {2, 2}}; 48 49 auto cnt = s.count(1); 50 assert(cnt == 3); 51 }