libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

max_load_factor.pass.cpp (1920B)


      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 
     20 #ifdef _LIBCPP_DEBUG
     21 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     22 #endif
     23 
     24 #include <unordered_map>
     25 #include <string>
     26 #include <cassert>
     27 
     28 #include "test_macros.h"
     29 #include "min_allocator.h"
     30 
     31 int main()
     32 {
     33     {
     34         typedef std::unordered_map<int, std::string> C;
     35         const C c;
     36         assert(c.max_load_factor() == 1);
     37     }
     38     {
     39         typedef std::unordered_map<int, std::string> C;
     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 TEST_STD_VER >= 11
     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         const C c;
     50         assert(c.max_load_factor() == 1);
     51     }
     52     {
     53         typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
     54                             min_allocator<std::pair<const int, std::string>>> C;
     55         C c;
     56         assert(c.max_load_factor() == 1);
     57         c.max_load_factor(2.5);
     58         assert(c.max_load_factor() == 2.5);
     59     }
     60 #endif
     61 #if _LIBCPP_DEBUG_LEVEL >= 1
     62     {
     63         typedef std::unordered_map<int, std::string> C;
     64         C c;
     65         c.max_load_factor(0);
     66         assert(false);
     67     }
     68 #endif
     69 }