libcxx

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

bucket_size.pass.cpp (2107B)


      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_set>
     11 
     12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
     13 //           class Alloc = allocator<Value>>
     14 // class unordered_set
     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_set>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 #include "min_allocator.h"
     27 
     28 int main()
     29 {
     30     {
     31         typedef std::unordered_set<int> C;
     32         typedef int P;
     33         P a[] =
     34         {
     35             P(1),
     36             P(2),
     37             P(3),
     38             P(4),
     39             P(1),
     40             P(2)
     41         };
     42         const C c(std::begin(a), std::end(a));
     43         assert(c.bucket_count() >= 5);
     44         LIBCPP_ASSERT(c.bucket_size(0) == 0);
     45         LIBCPP_ASSERT(c.bucket_size(1) == 1);
     46         LIBCPP_ASSERT(c.bucket_size(2) == 1);
     47         LIBCPP_ASSERT(c.bucket_size(3) == 1);
     48         LIBCPP_ASSERT(c.bucket_size(4) == 1);
     49     }
     50 #if TEST_STD_VER >= 11
     51     {
     52         typedef std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> C;
     53         typedef int P;
     54         P a[] =
     55         {
     56             P(1),
     57             P(2),
     58             P(3),
     59             P(4),
     60             P(1),
     61             P(2)
     62         };
     63         const C c(std::begin(a), std::end(a));
     64         assert(c.bucket_count() >= 5);
     65         LIBCPP_ASSERT(c.bucket_size(0) == 0);
     66         LIBCPP_ASSERT(c.bucket_size(1) == 1);
     67         LIBCPP_ASSERT(c.bucket_size(2) == 1);
     68         LIBCPP_ASSERT(c.bucket_size(3) == 1);
     69         LIBCPP_ASSERT(c.bucket_size(4) == 1);
     70     }
     71 #endif
     72 #if _LIBCPP_DEBUG_LEVEL >= 1
     73     {
     74         typedef std::unordered_set<int> C;
     75         C c;
     76         C::size_type i = c.bucket_size(3);
     77         assert(false);
     78     }
     79 #endif
     80 }