libcxx

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

assign_move.pass.cpp (7132B)


      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_set
     17 
     18 // unordered_set& operator=(unordered_set&& u);
     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 test_allocator<int> A;
     36         typedef std::unordered_set<int,
     37                                    test_hash<std::hash<int> >,
     38                                    test_compare<std::equal_to<int> >,
     39                                    A
     40                                    > C;
     41         typedef int P;
     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(a, a + 2,
     58             7,
     59             test_hash<std::hash<int> >(2),
     60             test_compare<std::equal_to<int> >(3),
     61             A(4)
     62            );
     63         c = std::move(c0);
     64         LIBCPP_ASSERT(c.bucket_count() == 7);
     65         assert(c.size() == 4);
     66         assert(c.count(1) == 1);
     67         assert(c.count(2) == 1);
     68         assert(c.count(3) == 1);
     69         assert(c.count(4) == 1);
     70         assert(c.hash_function() == test_hash<std::hash<int> >(8));
     71         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
     72         assert(c.get_allocator() == A(4));
     73         assert(!c.empty());
     74         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
     75         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
     76         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     77         assert(c.max_load_factor() == 1);
     78     }
     79     {
     80         typedef test_allocator<int> A;
     81         typedef std::unordered_set<int,
     82                                    test_hash<std::hash<int> >,
     83                                    test_compare<std::equal_to<int> >,
     84                                    A
     85                                    > C;
     86         typedef int P;
     87         P a[] =
     88         {
     89             P(1),
     90             P(2),
     91             P(3),
     92             P(4),
     93             P(1),
     94             P(2)
     95         };
     96         C c0(a, a + sizeof(a)/sizeof(a[0]),
     97             7,
     98             test_hash<std::hash<int> >(8),
     99             test_compare<std::equal_to<int> >(9),
    100             A(10)
    101            );
    102         C c(a, a + 2,
    103             7,
    104             test_hash<std::hash<int> >(2),
    105             test_compare<std::equal_to<int> >(3),
    106             A(10)
    107            );
    108         c = std::move(c0);
    109         LIBCPP_ASSERT(c.bucket_count() == 7);
    110         assert(c.size() == 4);
    111         assert(c.count(1) == 1);
    112         assert(c.count(2) == 1);
    113         assert(c.count(3) == 1);
    114         assert(c.count(4) == 1);
    115         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    116         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    117         assert(c.get_allocator() == A(10));
    118         assert(!c.empty());
    119         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    120         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    121         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    122         assert(c.max_load_factor() == 1);
    123     }
    124     {
    125         typedef other_allocator<int> A;
    126         typedef std::unordered_set<int,
    127                                    test_hash<std::hash<int> >,
    128                                    test_compare<std::equal_to<int> >,
    129                                    A
    130                                    > C;
    131         typedef int P;
    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(10)
    146            );
    147         C c(a, a + 2,
    148             7,
    149             test_hash<std::hash<int> >(2),
    150             test_compare<std::equal_to<int> >(3),
    151             A(4)
    152            );
    153         c = std::move(c0);
    154         LIBCPP_ASSERT(c.bucket_count() == 7);
    155         assert(c.size() == 4);
    156         assert(c.count(1) == 1);
    157         assert(c.count(2) == 1);
    158         assert(c.count(3) == 1);
    159         assert(c.count(4) == 1);
    160         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    161         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    162         assert(c.get_allocator() == A(10));
    163         assert(!c.empty());
    164         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    165         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    166         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    167         assert(c.max_load_factor() == 1);
    168     }
    169     {
    170         typedef min_allocator<int> A;
    171         typedef std::unordered_set<int,
    172                                    test_hash<std::hash<int> >,
    173                                    test_compare<std::equal_to<int> >,
    174                                    A
    175                                    > C;
    176         typedef int P;
    177         P a[] =
    178         {
    179             P(1),
    180             P(2),
    181             P(3),
    182             P(4),
    183             P(1),
    184             P(2)
    185         };
    186         C c0(a, a + sizeof(a)/sizeof(a[0]),
    187             7,
    188             test_hash<std::hash<int> >(8),
    189             test_compare<std::equal_to<int> >(9),
    190             A()
    191            );
    192         C c(a, a + 2,
    193             7,
    194             test_hash<std::hash<int> >(2),
    195             test_compare<std::equal_to<int> >(3),
    196             A()
    197            );
    198         c = std::move(c0);
    199         LIBCPP_ASSERT(c.bucket_count() == 7);
    200         assert(c.size() == 4);
    201         assert(c.count(1) == 1);
    202         assert(c.count(2) == 1);
    203         assert(c.count(3) == 1);
    204         assert(c.count(4) == 1);
    205         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    206         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    207         assert(c.get_allocator() == A());
    208         assert(!c.empty());
    209         assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
    210         assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
    211         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    212         assert(c.max_load_factor() == 1);
    213     }
    214 }