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 // <unordered_set> 11 12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, 13 // class Alloc = allocator<Value>> 14 // class unordered_set 15 16 // void reserve(size_type n); 17 18 #include <unordered_set> 19 #include <cassert> 20 21 void test(const std::unordered_set<int>& c) 22 { 23 assert(c.size() == 4); 24 assert(c.count(1) == 1); 25 assert(c.count(2) == 1); 26 assert(c.count(3) == 1); 27 assert(c.count(4) == 1); 28 } 29 30 int main() 31 { 32 { 33 typedef std::unordered_set<int> C; 34 typedef int P; 35 P a[] = 36 { 37 P(1), 38 P(2), 39 P(3), 40 P(4), 41 P(1), 42 P(2) 43 }; 44 C c(a, a + sizeof(a)/sizeof(a[0])); 45 test(c); 46 assert(c.bucket_count() >= 5); 47 c.reserve(3); 48 assert(c.bucket_count() == 5); 49 test(c); 50 c.max_load_factor(2); 51 c.reserve(3); 52 assert(c.bucket_count() >= 2); 53 test(c); 54 c.reserve(31); 55 assert(c.bucket_count() >= 16); 56 test(c); 57 } 58 } 59