libcxx

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

bucket_size.pass.cpp (2382B)


      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 "test_macros.h"
     27 #include "min_allocator.h"
     28 
     29 int main()
     30 {
     31     {
     32         typedef std::unordered_map<int, std::string> C;
     33         typedef std::pair<int, std::string> P;
     34         P a[] =
     35         {
     36             P(1, "one"),
     37             P(2, "two"),
     38             P(3, "three"),
     39             P(4, "four"),
     40             P(1, "four"),
     41             P(2, "four"),
     42         };
     43         const C c(std::begin(a), std::end(a));
     44         assert(c.bucket_count() >= 5);
     45         LIBCPP_ASSERT(c.bucket_size(0) == 0);
     46         LIBCPP_ASSERT(c.bucket_size(1) == 1);
     47         LIBCPP_ASSERT(c.bucket_size(2) == 1);
     48         LIBCPP_ASSERT(c.bucket_size(3) == 1);
     49         LIBCPP_ASSERT(c.bucket_size(4) == 1);
     50     }
     51 #if TEST_STD_VER >= 11
     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         typedef std::pair<int, std::string> P;
     56         P a[] =
     57         {
     58             P(1, "one"),
     59             P(2, "two"),
     60             P(3, "three"),
     61             P(4, "four"),
     62             P(1, "four"),
     63             P(2, "four"),
     64         };
     65         const C c(std::begin(a), std::end(a));
     66         assert(c.bucket_count() >= 5);
     67         LIBCPP_ASSERT(c.bucket_size(0) == 0);
     68         LIBCPP_ASSERT(c.bucket_size(1) == 1);
     69         LIBCPP_ASSERT(c.bucket_size(2) == 1);
     70         LIBCPP_ASSERT(c.bucket_size(3) == 1);
     71         LIBCPP_ASSERT(c.bucket_size(4) == 1);
     72     }
     73 #endif
     74 #if _LIBCPP_DEBUG_LEVEL >= 1
     75     {
     76         typedef std::unordered_map<int, std::string> C;
     77         C c;
     78         C::size_type i = c.bucket_size(3);
     79         assert(false);
     80     }
     81 #endif
     82 }