libcxx

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

allocator.pass.cpp (5318B)


      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_multimap
     15 
     16 // explicit unordered_multimap(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 
     28 int main()
     29 {
     30     {
     31         typedef std::unordered_multimap<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(test_allocator<std::pair<const NotConstructible, NotConstructible> >(10));
     38         LIBCPP_ASSERT(c.bucket_count() == 0);
     39         assert(c.hash_function() == test_hash<std::hash<NotConstructible> >());
     40         assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >());
     41         assert(c.get_allocator() ==
     42                (test_allocator<std::pair<const NotConstructible, NotConstructible> >(10)));
     43         assert(c.size() == 0);
     44         assert(c.empty());
     45         assert(std::distance(c.begin(), c.end()) == 0);
     46         assert(c.load_factor() == 0);
     47         assert(c.max_load_factor() == 1);
     48     }
     49 #if TEST_STD_VER >= 11
     50     {
     51         typedef std::unordered_multimap<NotConstructible, NotConstructible,
     52                                    test_hash<std::hash<NotConstructible> >,
     53                                    test_compare<std::equal_to<NotConstructible> >,
     54                                    min_allocator<std::pair<const NotConstructible,
     55                                                                   NotConstructible> >
     56                                    > C;
     57         C c(min_allocator<std::pair<const NotConstructible, NotConstructible> >{});
     58         LIBCPP_ASSERT(c.bucket_count() == 0);
     59         assert(c.hash_function() == test_hash<std::hash<NotConstructible> >());
     60         assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >());
     61         assert(c.get_allocator() ==
     62                (min_allocator<std::pair<const NotConstructible, NotConstructible> >()));
     63         assert(c.size() == 0);
     64         assert(c.empty());
     65         assert(std::distance(c.begin(), c.end()) == 0);
     66         assert(c.load_factor() == 0);
     67         assert(c.max_load_factor() == 1);
     68     }
     69     {
     70         typedef explicit_allocator<std::pair<const NotConstructible, NotConstructible>> A;
     71         typedef std::unordered_multimap<NotConstructible, NotConstructible,
     72                                    test_hash<std::hash<NotConstructible> >,
     73                                    test_compare<std::equal_to<NotConstructible> >,
     74                                    A
     75                                    > C;
     76         C c(A{});
     77         LIBCPP_ASSERT(c.bucket_count() == 0);
     78         assert(c.hash_function() == test_hash<std::hash<NotConstructible> >());
     79         assert(c.key_eq() == test_compare<std::equal_to<NotConstructible> >());
     80         assert(c.get_allocator() == A{});
     81         assert(c.size() == 0);
     82         assert(c.empty());
     83         assert(std::distance(c.begin(), c.end()) == 0);
     84         assert(c.load_factor() == 0);
     85         assert(c.max_load_factor() == 1);
     86     }
     87 #if TEST_STD_VER > 11
     88     {
     89         typedef NotConstructible T;
     90         typedef test_allocator<std::pair<const T, T>> A;
     91         typedef test_hash<std::hash<T>> HF;
     92         typedef test_compare<std::equal_to<T>> Comp;
     93         typedef std::unordered_multimap<T, T, HF, Comp, A> C;
     94 
     95         A a(10);
     96         C c(2, a);
     97         LIBCPP_ASSERT(c.bucket_count() == 2);
     98         assert(c.hash_function() == HF());
     99         assert(c.key_eq() == Comp());
    100         assert(c.get_allocator() == a);
    101         assert(c.size() == 0);
    102         assert(c.empty());
    103         assert(std::distance(c.begin(), c.end()) == 0);
    104         assert(c.load_factor() == 0);
    105         assert(c.max_load_factor() == 1);
    106     }
    107     {
    108         typedef NotConstructible T;
    109         typedef test_allocator<std::pair<const T, T>> A;
    110         typedef test_hash<std::hash<T>> HF;
    111         typedef test_compare<std::equal_to<T>> Comp;
    112         typedef std::unordered_multimap<T, T, HF, Comp, A> C;
    113 
    114         A a(10);
    115         HF hf(12);
    116         C c(2, hf, a);
    117         LIBCPP_ASSERT(c.bucket_count() == 2);
    118         assert(c.hash_function() == hf);
    119         assert(!(c.hash_function() == HF()));
    120         assert(c.key_eq() == Comp());
    121         assert(c.get_allocator() == a);
    122         assert(c.size() == 0);
    123         assert(c.empty());
    124         assert(std::distance(c.begin(), c.end()) == 0);
    125         assert(c.load_factor() == 0);
    126         assert(c.max_load_factor() == 1);
    127     }
    128 #endif
    129 #endif
    130 }