bucket.pass.cpp (1874B)
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 // size_type bucket(const key_type& __k) const; 17 18 #ifdef _LIBCPP_DEBUG 19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 20 #endif 21 22 #include <unordered_set> 23 #include <cassert> 24 25 #include "test_macros.h" 26 #include "min_allocator.h" 27 28 int main() 29 { 30 { 31 typedef std::unordered_set<int> C; 32 typedef int P; 33 P a[] = 34 { 35 P(1), 36 P(2), 37 P(3), 38 P(4), 39 P(1), 40 P(2) 41 }; 42 const C c(std::begin(a), std::end(a)); 43 size_t bc = c.bucket_count(); 44 assert(bc >= 5); 45 for (size_t i = 0; i < 13; ++i) 46 LIBCPP_ASSERT(c.bucket(i) == i % bc); 47 } 48 #if TEST_STD_VER >= 11 49 { 50 typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C; 51 typedef int P; 52 P a[] = 53 { 54 P(1), 55 P(2), 56 P(3), 57 P(4), 58 P(1), 59 P(2) 60 }; 61 const C c(std::begin(a), std::end(a)); 62 size_t bc = c.bucket_count(); 63 assert(bc >= 5); 64 for (size_t i = 0; i < 13; ++i) 65 LIBCPP_ASSERT(c.bucket(i) == i % bc); 66 } 67 #endif 68 #if _LIBCPP_DEBUG_LEVEL >= 1 69 { 70 typedef std::unordered_set<int> C; 71 C c; 72 C::size_type i = c.bucket(3); 73 assert(false); 74 } 75 #endif 76 }