Home | History | Annotate | Download | only in unord.multimap
      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 // size_type bucket(const key_type& __k) const;
     17 
     18 #ifdef _LIBCPP_DEBUG
     19 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
     20 #endif
     21 
     22 #include <unordered_map>
     23 #include <string>
     24 #include <cassert>
     25 
     26 #include "min_allocator.h"
     27 
     28 int main()
     29 {
     30     {
     31         typedef std::unordered_multimap<int, std::string> C;
     32         typedef std::pair<int, std::string> P;
     33         P a[] =
     34         {
     35             P(1, "one"),
     36             P(2, "two"),
     37             P(3, "three"),
     38             P(4, "four"),
     39             P(1, "four"),
     40             P(2, "four"),
     41         };
     42         const C c(std::begin(a), std::end(a));
     43         size_t bc = c.bucket_count();
     44         assert(bc >= 7);
     45         for (size_t i = 0; i < 13; ++i)
     46             assert(c.bucket(i) == i % bc);
     47     }
     48 #if __cplusplus >= 201103L
     49     {
     50         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
     51                             min_allocator<std::pair<const int, std::string>>> C;
     52         typedef std::pair<int, std::string> P;
     53         P a[] =
     54         {
     55             P(1, "one"),
     56             P(2, "two"),
     57             P(3, "three"),
     58             P(4, "four"),
     59             P(1, "four"),
     60             P(2, "four"),
     61         };
     62         const C c(std::begin(a), std::end(a));
     63         size_t bc = c.bucket_count();
     64         assert(bc >= 7);
     65         for (size_t i = 0; i < 13; ++i)
     66             assert(c.bucket(i) == i % bc);
     67     }
     68 #endif
     69 #if _LIBCPP_DEBUG_LEVEL >= 1
     70     {
     71         typedef std::unordered_multimap<int, std::string> C;
     72         C c;
     73         C::size_type i = c.bucket(3);
     74         assert(false);
     75     }
     76 #endif
     77 }
     78