size_hash_equal_allocator.pass.cpp revision d4badbbc5a4c63fa9c644d4ae78ec0e38564c8dc
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// unordered_map(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); 17 18#include <unordered_map> 19#include <cassert> 20 21#include "test_macros.h" 22#include "../../../NotConstructible.h" 23#include "../../../test_compare.h" 24#include "../../../test_hash.h" 25#include "test_allocator.h" 26#include "min_allocator.h" 27 28int main() 29{ 30 { 31 typedef std::unordered_map<NotConstructible, NotConstructible, 32 test_hash<std::hash<NotConstructible> >, 33 test_compare<std::equal_to<NotConstructible> >, 34 test_allocator<std::pair<const NotConstructible, 35 NotConstructible> > 36 > C; 37 C c(7, 38 test_hash<std::hash<NotConstructible> >(8), 39 test_compare<std::equal_to<NotConstructible> >(9), 40 test_allocator<std::pair<const NotConstructible, NotConstructible> >(10) 41 ); 42 LIBCPP_ASSERT(c.bucket_count() == 7); 43 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); 44 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); 45 assert(c.get_allocator() == 46 (test_allocator<std::pair<const NotConstructible, NotConstructible> >(10))); 47 assert(c.size() == 0); 48 assert(c.empty()); 49 assert(std::distance(c.begin(), c.end()) == 0); 50 assert(c.load_factor() == 0); 51 assert(c.max_load_factor() == 1); 52 } 53#if TEST_STD_VER >= 11 54 { 55 typedef std::unordered_map<NotConstructible, NotConstructible, 56 test_hash<std::hash<NotConstructible> >, 57 test_compare<std::equal_to<NotConstructible> >, 58 min_allocator<std::pair<const NotConstructible, 59 NotConstructible> > 60 > C; 61 C c(7, 62 test_hash<std::hash<NotConstructible> >(8), 63 test_compare<std::equal_to<NotConstructible> >(9), 64 min_allocator<std::pair<const NotConstructible, NotConstructible> >() 65 ); 66 LIBCPP_ASSERT(c.bucket_count() == 7); 67 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); 68 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); 69 assert(c.get_allocator() == 70 (min_allocator<std::pair<const NotConstructible, NotConstructible> >())); 71 assert(c.size() == 0); 72 assert(c.empty()); 73 assert(std::distance(c.begin(), c.end()) == 0); 74 assert(c.load_factor() == 0); 75 assert(c.max_load_factor() == 1); 76 } 77 { 78 typedef explicit_allocator<std::pair<const NotConstructible, NotConstructible> > A; 79 typedef std::unordered_map<NotConstructible, NotConstructible, 80 test_hash<std::hash<NotConstructible> >, 81 test_compare<std::equal_to<NotConstructible> >, 82 A 83 > C; 84 C c(7, 85 test_hash<std::hash<NotConstructible> >(8), 86 test_compare<std::equal_to<NotConstructible> >(9), 87 A{} 88 ); 89 LIBCPP_ASSERT(c.bucket_count() == 7); 90 assert(c.hash_function() == test_hash<std::hash<NotConstructible> >(8)); 91 assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >(9)); 92 assert(c.get_allocator() == A{}); 93 assert(c.size() == 0); 94 assert(c.empty()); 95 assert(std::distance(c.begin(), c.end()) == 0); 96 assert(c.load_factor() == 0); 97 assert(c.max_load_factor() == 1); 98 } 99#endif 100} 101