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 // <set> 11 12 // class set 13 14 // size_type count(const key_type& k) const; 15 16 #include <set> 17 #include <cassert> 18 19 #include "min_allocator.h" 20 #include "private_constructor.hpp" 21 22 int main() 23 { 24 { 25 typedef int V; 26 typedef std::set<int> M; 27 typedef M::size_type R; 28 V ar[] = 29 { 30 5, 31 6, 32 7, 33 8, 34 9, 35 10, 36 11, 37 12 38 }; 39 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 40 R r = m.count(5); 41 assert(r == 1); 42 r = m.count(6); 43 assert(r == 1); 44 r = m.count(7); 45 assert(r == 1); 46 r = m.count(8); 47 assert(r == 1); 48 r = m.count(9); 49 assert(r == 1); 50 r = m.count(10); 51 assert(r == 1); 52 r = m.count(11); 53 assert(r == 1); 54 r = m.count(12); 55 assert(r == 1); 56 r = m.count(4); 57 assert(r == 0); 58 } 59 #if __cplusplus >= 201103L 60 { 61 typedef int V; 62 typedef std::set<int, std::less<int>, min_allocator<int>> M; 63 typedef M::size_type R; 64 V ar[] = 65 { 66 5, 67 6, 68 7, 69 8, 70 9, 71 10, 72 11, 73 12 74 }; 75 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 76 R r = m.count(5); 77 assert(r == 1); 78 r = m.count(6); 79 assert(r == 1); 80 r = m.count(7); 81 assert(r == 1); 82 r = m.count(8); 83 assert(r == 1); 84 r = m.count(9); 85 assert(r == 1); 86 r = m.count(10); 87 assert(r == 1); 88 r = m.count(11); 89 assert(r == 1); 90 r = m.count(12); 91 assert(r == 1); 92 r = m.count(4); 93 assert(r == 0); 94 } 95 #endif 96 #if _LIBCPP_STD_VER > 11 97 { 98 typedef int V; 99 typedef std::set<int, std::less<>> M; 100 typedef M::size_type R; 101 V ar[] = 102 { 103 5, 104 6, 105 7, 106 8, 107 9, 108 10, 109 11, 110 12 111 }; 112 const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); 113 R r = m.count(5); 114 assert(r == 1); 115 r = m.count(6); 116 assert(r == 1); 117 r = m.count(7); 118 assert(r == 1); 119 r = m.count(8); 120 assert(r == 1); 121 r = m.count(9); 122 assert(r == 1); 123 r = m.count(10); 124 assert(r == 1); 125 r = m.count(11); 126 assert(r == 1); 127 r = m.count(12); 128 assert(r == 1); 129 r = m.count(4); 130 assert(r == 0); 131 } 132 { 133 typedef PrivateConstructor V; 134 typedef std::set<V, std::less<>> M; 135 typedef M::size_type R; 136 137 M m; 138 m.insert ( V::make ( 5 )); 139 m.insert ( V::make ( 6 )); 140 m.insert ( V::make ( 7 )); 141 m.insert ( V::make ( 8 )); 142 m.insert ( V::make ( 9 )); 143 m.insert ( V::make ( 10 )); 144 m.insert ( V::make ( 11 )); 145 m.insert ( V::make ( 12 )); 146 147 R r = m.count(5); 148 assert(r == 1); 149 r = m.count(6); 150 assert(r == 1); 151 r = m.count(7); 152 assert(r == 1); 153 r = m.count(8); 154 assert(r == 1); 155 r = m.count(9); 156 assert(r == 1); 157 r = m.count(10); 158 assert(r == 1); 159 r = m.count(11); 160 assert(r == 1); 161 r = m.count(12); 162 assert(r == 1); 163 r = m.count(4); 164 assert(r == 0); 165 } 166 #endif 167 168 } 169