Home | History | Annotate | Download | only in unord.multimap.cnstr
      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 // unordered_multimap(const unordered_multimap& u, const allocator_type& a);
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 #include <cfloat>
     22 
     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<int, std::string,
     32                                    test_hash<std::hash<int> >,
     33                                    test_compare<std::equal_to<int> >,
     34                                    test_allocator<std::pair<const int, std::string> >
     35                                    > C;
     36         typedef std::pair<int, std::string> P;
     37         P a[] =
     38         {
     39             P(1, "one"),
     40             P(2, "two"),
     41             P(3, "three"),
     42             P(4, "four"),
     43             P(1, "four"),
     44             P(2, "four"),
     45         };
     46         C c0(a, a + sizeof(a)/sizeof(a[0]),
     47             7,
     48             test_hash<std::hash<int> >(8),
     49             test_compare<std::equal_to<int> >(9),
     50             test_allocator<std::pair<const int, std::string> >(10)
     51            );
     52         C c(c0, test_allocator<std::pair<const int, std::string> >(5));
     53         assert(c.bucket_count() == 7);
     54         assert(c.size() == 6);
     55         C::const_iterator i = c.cbegin();
     56         assert(i->first == 1);
     57         assert(i->second == "one");
     58         ++i;
     59         assert(i->first == 1);
     60         assert(i->second == "four");
     61         ++i;
     62         assert(i->first == 2);
     63         assert(i->second == "two");
     64         ++i;
     65         assert(i->first == 2);
     66         assert(i->second == "four");
     67         ++i;
     68         assert(i->first == 3);
     69         assert(i->second == "three");
     70         ++i;
     71         assert(i->first == 4);
     72         assert(i->second == "four");
     73         assert(c.hash_function() == test_hash<std::hash<int> >(8));
     74         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
     75         assert(c.get_allocator() ==
     76                (test_allocator<std::pair<const int, std::string> >(5)));
     77         assert(!c.empty());
     78         assert(std::distance(c.begin(), c.end()) == c.size());
     79         assert(std::distance(c.cbegin(), c.cend()) == c.size());
     80         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     81         assert(c.max_load_factor() == 1);
     82     }
     83 #if __cplusplus >= 201103L
     84     {
     85         typedef std::unordered_multimap<int, std::string,
     86                                    test_hash<std::hash<int> >,
     87                                    test_compare<std::equal_to<int> >,
     88                                    min_allocator<std::pair<const int, std::string> >
     89                                    > C;
     90         typedef std::pair<int, std::string> P;
     91         P a[] =
     92         {
     93             P(1, "one"),
     94             P(2, "two"),
     95             P(3, "three"),
     96             P(4, "four"),
     97             P(1, "four"),
     98             P(2, "four"),
     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             min_allocator<std::pair<const int, std::string> >()
    105            );
    106         C c(c0, min_allocator<std::pair<const int, std::string> >());
    107         assert(c.bucket_count() == 7);
    108         assert(c.size() == 6);
    109         C::const_iterator i = c.cbegin();
    110         assert(i->first == 1);
    111         assert(i->second == "one");
    112         ++i;
    113         assert(i->first == 1);
    114         assert(i->second == "four");
    115         ++i;
    116         assert(i->first == 2);
    117         assert(i->second == "two");
    118         ++i;
    119         assert(i->first == 2);
    120         assert(i->second == "four");
    121         ++i;
    122         assert(i->first == 3);
    123         assert(i->second == "three");
    124         ++i;
    125         assert(i->first == 4);
    126         assert(i->second == "four");
    127         assert(c.hash_function() == test_hash<std::hash<int> >(8));
    128         assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
    129         assert(c.get_allocator() ==
    130                (min_allocator<std::pair<const int, std::string> >()));
    131         assert(!c.empty());
    132         assert(std::distance(c.begin(), c.end()) == c.size());
    133         assert(std::distance(c.cbegin(), c.cend()) == c.size());
    134         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
    135         assert(c.max_load_factor() == 1);
    136     }
    137 #endif
    138 }
    139