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 // pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
     17 
     18 #include <unordered_map>
     19 #include <string>
     20 #include <cassert>
     21 
     22 #include "min_allocator.h"
     23 
     24 int main()
     25 {
     26     {
     27         typedef std::unordered_multimap<int, std::string> C;
     28         typedef C::const_iterator I;
     29         typedef std::pair<int, std::string> P;
     30         P a[] =
     31         {
     32             P(10, "ten"),
     33             P(20, "twenty"),
     34             P(30, "thirty"),
     35             P(40, "forty"),
     36             P(50, "fifty"),
     37             P(50, "fiftyA"),
     38             P(50, "fiftyB"),
     39             P(60, "sixty"),
     40             P(70, "seventy"),
     41             P(80, "eighty"),
     42         };
     43         const C c(std::begin(a), std::end(a));
     44         std::pair<I, I> r = c.equal_range(30);
     45         assert(std::distance(r.first, r.second) == 1);
     46         assert(r.first->first == 30);
     47         assert(r.first->second == "thirty");
     48         r = c.equal_range(5);
     49         assert(std::distance(r.first, r.second) == 0);
     50         r = c.equal_range(50);
     51         assert(r.first->first == 50);
     52         assert(r.first->second == "fifty");
     53         ++r.first;
     54         assert(r.first->first == 50);
     55         assert(r.first->second == "fiftyA");
     56         ++r.first;
     57         assert(r.first->first == 50);
     58         assert(r.first->second == "fiftyB");
     59     }
     60 #if __cplusplus >= 201103L
     61     {
     62         typedef std::unordered_multimap<int, std::string, std::hash<int>, std::equal_to<int>,
     63                             min_allocator<std::pair<const int, std::string>>> C;
     64         typedef C::const_iterator I;
     65         typedef std::pair<int, std::string> P;
     66         P a[] =
     67         {
     68             P(10, "ten"),
     69             P(20, "twenty"),
     70             P(30, "thirty"),
     71             P(40, "forty"),
     72             P(50, "fifty"),
     73             P(50, "fiftyA"),
     74             P(50, "fiftyB"),
     75             P(60, "sixty"),
     76             P(70, "seventy"),
     77             P(80, "eighty"),
     78         };
     79         const C c(std::begin(a), std::end(a));
     80         std::pair<I, I> r = c.equal_range(30);
     81         assert(std::distance(r.first, r.second) == 1);
     82         assert(r.first->first == 30);
     83         assert(r.first->second == "thirty");
     84         r = c.equal_range(5);
     85         assert(std::distance(r.first, r.second) == 0);
     86         r = c.equal_range(50);
     87         assert(r.first->first == 50);
     88         assert(r.first->second == "fifty");
     89         ++r.first;
     90         assert(r.first->first == 50);
     91         assert(r.first->second == "fiftyA");
     92         ++r.first;
     93         assert(r.first->first == 50);
     94         assert(r.first->second == "fiftyB");
     95     }
     96 #endif
     97 }
     98