libcxx

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

assign_copy.pass.cpp (6353B)


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