libcxx

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

move_alloc.pass.cpp (6807B)


      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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <unordered_set>
     13 
     14 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
     15 //           class Alloc = allocator<Value>>
     16 // class unordered_multiset
     17 
     18 // unordered_multiset(unordered_multiset&& u, const allocator_type& a);
     19 
     20 #include <unordered_set>
     21 #include <cassert>
     22 #include <cfloat>
     23 #include <cmath>
     24 #include <cstddef>
     25 
     26 #include "test_macros.h"
     27 #include "../../../test_compare.h"
     28 #include "../../../test_hash.h"
     29 #include "test_allocator.h"
     30 #include "min_allocator.h"
     31 
     32 int main()
     33 {
     34     {
     35         typedef int P;
     36         typedef test_allocator<int> A;
     37         typedef std::unordered_multiset<int,
     38                                    test_hash<std::hash<int> >,
     39                                    test_compare<std::equal_to<int> >,
     40                                    A
     41                                    > C;
     42         P a[] =
     43         {
     44             P(1),
     45             P(2),
     46             P(3),
     47             P(4),
     48             P(1),
     49             P(2)
     50         };
     51         C c0(a, a + sizeof(a)/sizeof(a[0]),
     52             7,
     53             test_hash<std::hash<int> >(8),
     54             test_compare<std::equal_to<int> >(9),
     55             A(10)
     56            );
     57         C c(std::move(c0), A(12));
     58         assert(c.bucket_count() >= 7);
     59         assert(c.size() == 6);
     60         C::const_iterator i = c.cbegin();
     61         assert(*i == 1);
     62         ++i;
     63         assert(*i == 1);
     64         ++i;
     65         assert(*i == 2);
     66         ++i;
     67         assert(*i == 2);
     68         ++i;
     69         assert(*i == 3);
     70         ++i;
     71         assert(*i == 4);
     72         assert(c.hash_function() == test_hash<std::hash<int> >(8));
     73         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
     74         assert(c.get_allocator() == A(12));
     75         assert(!c.empty());
     76         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
     77         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
     78         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     79         assert(c.max_load_factor() == 1);
     80 
     81         assert(c0.empty());
     82     }
     83     {
     84         typedef int P;
     85         typedef test_allocator<int> A;
     86         typedef std::unordered_multiset<int,
     87                                    test_hash<std::hash<int> >,
     88                                    test_compare<std::equal_to<int> >,
     89                                    A
     90                                    > C;
     91         P a[] =
     92         {
     93             P(1),
     94             P(2),
     95             P(3),
     96             P(4),
     97             P(1),
     98             P(2)
     99         };
    100         C c0(a, a + sizeof(a)/sizeof(a[0]),
    101             7,
    102             test_hash<std::hash<int> >(8),
    103             test_compare<std::equal_to<int> >(9),
    104             A(10)
    105            );
    106         C c(std::move(c0), A(10));
    107         LIBCPP_ASSERT(c.bucket_count() == 7);
    108         assert(c.size() == 6);
    109         assert(c.count(1) == 2);
    110         assert(c.count(2) == 2);
    111         assert(c.count(3) == 1);
    112         assert(c.count(4) == 1);
    113         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    114         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    115         assert(c.get_allocator() == A(10));
    116         assert(!c.empty());
    117         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    118         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    119         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    120         assert(c.max_load_factor() == 1);
    121 
    122         assert(c0.empty());
    123     }
    124     {
    125         typedef int P;
    126         typedef min_allocator<int> A;
    127         typedef std::unordered_multiset<int,
    128                                    test_hash<std::hash<int> >,
    129                                    test_compare<std::equal_to<int> >,
    130                                    A
    131                                    > C;
    132         P a[] =
    133         {
    134             P(1),
    135             P(2),
    136             P(3),
    137             P(4),
    138             P(1),
    139             P(2)
    140         };
    141         C c0(a, a + sizeof(a)/sizeof(a[0]),
    142             7,
    143             test_hash<std::hash<int> >(8),
    144             test_compare<std::equal_to<int> >(9),
    145             A()
    146            );
    147         C c(std::move(c0), A());
    148         assert(c.bucket_count() >= 7);
    149         assert(c.size() == 6);
    150         assert(c.count(1) == 2);
    151         assert(c.count(2) == 2);
    152         assert(c.count(3) == 1);
    153         assert(c.count(4) == 1);
    154         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    155         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    156         assert(c.get_allocator() == A());
    157         assert(!c.empty());
    158         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    159         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    160         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    161         assert(c.max_load_factor() == 1);
    162 
    163         assert(c0.empty());
    164     }
    165     {
    166         typedef int P;
    167         typedef min_allocator<int> A;
    168         typedef std::unordered_multiset<int,
    169                                    test_hash<std::hash<int> >,
    170                                    test_compare<std::equal_to<int> >,
    171                                    A
    172                                    > C;
    173         P a[] =
    174         {
    175             P(1),
    176             P(2),
    177             P(3),
    178             P(4),
    179             P(1),
    180             P(2)
    181         };
    182         C c0(a, a + sizeof(a)/sizeof(a[0]),
    183             7,
    184             test_hash<std::hash<int> >(8),
    185             test_compare<std::equal_to<int> >(9),
    186             A()
    187            );
    188         C c(std::move(c0), A());
    189         LIBCPP_ASSERT(c.bucket_count() == 7);
    190         assert(c.size() == 6);
    191         assert(c.count(1) == 2);
    192         assert(c.count(2) == 2);
    193         assert(c.count(3) == 1);
    194         assert(c.count(4) == 1);
    195         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    196         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    197         assert(c.get_allocator() == A());
    198         assert(!c.empty());
    199         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    200         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    201         assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    202         assert(c.max_load_factor() == 1);
    203 
    204         assert(c0.empty());
    205     }
    206 }