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(initializer_list<value_type> il, size_type n);
     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 
     27 int main()
     28 {
     29 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     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         C c({
     38                 P(1, "one"),
     39                 P(2, "two"),
     40                 P(3, "three"),
     41                 P(4, "four"),
     42                 P(1, "four"),
     43                 P(2, "four"),
     44             },
     45             7
     46            );
     47         assert(c.bucket_count() == 7);
     48         assert(c.size() == 6);
     49         typedef std::pair<C::const_iterator, C::const_iterator> Eq;
     50         Eq eq = c.equal_range(1);
     51         assert(std::distance(eq.first, eq.second) == 2);
     52         C::const_iterator i = eq.first;
     53         assert(i->first == 1);
     54         assert(i->second == "one");
     55         ++i;
     56         assert(i->first == 1);
     57         assert(i->second == "four");
     58         eq = c.equal_range(2);
     59         assert(std::distance(eq.first, eq.second) == 2);
     60         i = eq.first;
     61         assert(i->first == 2);
     62         assert(i->second == "two");
     63         ++i;
     64         assert(i->first == 2);
     65         assert(i->second == "four");
     66 
     67         eq = c.equal_range(3);
     68         assert(std::distance(eq.first, eq.second) == 1);
     69         i = eq.first;
     70         assert(i->first == 3);
     71         assert(i->second == "three");
     72         eq = c.equal_range(4);
     73         assert(std::distance(eq.first, eq.second) == 1);
     74         i = eq.first;
     75         assert(i->first == 4);
     76         assert(i->second == "four");
     77         assert(std::distance(c.begin(), c.end()) == c.size());
     78         assert(std::distance(c.cbegin(), c.cend()) == c.size());
     79         assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
     80         assert(c.max_load_factor() == 1);
     81         assert(c.hash_function() == test_hash<std::hash<int> >());
     82         assert(c.key_eq() == test_compare<std::equal_to<int> >());
     83         assert((c.get_allocator() == test_allocator<std::pair<const int, std::string> >()));
     84     }
     85 #endif  // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
     86 }
     87