bucket_size.pass.cpp revision 5e57142c5902c3f73a6fdcb8cab55e88ffb43a56
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_map> 11 12// template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>, 13// class Alloc = allocator<pair<const Key, T>>> 14// class unordered_map 15 16// size_type bucket_size(size_type n) const 17 18#ifdef _LIBCPP_DEBUG 19#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 20#endif 21 22#include <unordered_map> 23#include <string> 24#include <cassert> 25 26#include "../../min_allocator.h" 27 28int main() 29{ 30 { 31 typedef std::unordered_map<int, std::string> C; 32 typedef std::pair<int, std::string> P; 33 P a[] = 34 { 35 P(1, "one"), 36 P(2, "two"), 37 P(3, "three"), 38 P(4, "four"), 39 P(1, "four"), 40 P(2, "four"), 41 }; 42 const C c(std::begin(a), std::end(a)); 43 assert(c.bucket_count() >= 5); 44 assert(c.bucket_size(0) == 0); 45 assert(c.bucket_size(1) == 1); 46 assert(c.bucket_size(2) == 1); 47 assert(c.bucket_size(3) == 1); 48 assert(c.bucket_size(4) == 1); 49 } 50#if __cplusplus >= 201103L 51 { 52 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, 53 min_allocator<std::pair<const int, std::string>>> C; 54 typedef std::pair<int, std::string> P; 55 P a[] = 56 { 57 P(1, "one"), 58 P(2, "two"), 59 P(3, "three"), 60 P(4, "four"), 61 P(1, "four"), 62 P(2, "four"), 63 }; 64 const C c(std::begin(a), std::end(a)); 65 assert(c.bucket_count() >= 5); 66 assert(c.bucket_size(0) == 0); 67 assert(c.bucket_size(1) == 1); 68 assert(c.bucket_size(2) == 1); 69 assert(c.bucket_size(3) == 1); 70 assert(c.bucket_size(4) == 1); 71 } 72#endif 73#if _LIBCPP_DEBUG_LEVEL >= 1 74 { 75 typedef std::unordered_map<int, std::string> C; 76 C c; 77 C::size_type i = c.bucket_size(3); 78 assert(false); 79 } 80#endif 81} 82