max_load_factor.pass.cpp revision 824c19963e0263366047787b024a992afc2b1c54
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// float max_load_factor() const; 17// void max_load_factor(float mlf); 18 19#ifdef _LIBCPP_DEBUG2 20#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 21#endif 22 23#include <unordered_map> 24#include <string> 25#include <cassert> 26 27#include "../../min_allocator.h" 28 29int main() 30{ 31 { 32 typedef std::unordered_map<int, std::string> C; 33 typedef std::pair<int, std::string> P; 34 const C c; 35 assert(c.max_load_factor() == 1); 36 } 37 { 38 typedef std::unordered_map<int, std::string> C; 39 typedef std::pair<int, std::string> P; 40 C c; 41 assert(c.max_load_factor() == 1); 42 c.max_load_factor(2.5); 43 assert(c.max_load_factor() == 2.5); 44 } 45#if __cplusplus >= 201103L 46 { 47 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, 48 min_allocator<std::pair<const int, std::string>>> C; 49 typedef std::pair<int, std::string> P; 50 const C c; 51 assert(c.max_load_factor() == 1); 52 } 53 { 54 typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>, 55 min_allocator<std::pair<const int, std::string>>> C; 56 typedef std::pair<int, std::string> P; 57 C c; 58 assert(c.max_load_factor() == 1); 59 c.max_load_factor(2.5); 60 assert(c.max_load_factor() == 2.5); 61 } 62#endif 63#if _LIBCPP_DEBUG_LEVEL >= 1 64 { 65 typedef std::unordered_map<int, std::string> C; 66 C c; 67 c.max_load_factor(0); 68 assert(false); 69 } 70#endif 71} 72