Home | History | Annotate | Download | only in unord.multiset
      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 // pair<iterator, iterator> equal_range(const key_type& k);
     17 
     18 #include <unordered_set>
     19 #include <cassert>
     20 
     21 #include "min_allocator.h"
     22 
     23 int main()
     24 {
     25     {
     26         typedef std::unordered_multiset<int> C;
     27         typedef C::iterator I;
     28         typedef int P;
     29         P a[] =
     30         {
     31             P(10),
     32             P(20),
     33             P(30),
     34             P(40),
     35             P(50),
     36             P(50),
     37             P(50),
     38             P(60),
     39             P(70),
     40             P(80)
     41         };
     42         C c(std::begin(a), std::end(a));
     43         std::pair<I, I> r = c.equal_range(30);
     44         assert(std::distance(r.first, r.second) == 1);
     45         assert(*r.first == 30);
     46         r = c.equal_range(5);
     47         assert(std::distance(r.first, r.second) == 0);
     48         r = c.equal_range(50);
     49         assert(std::distance(r.first, r.second) == 3);
     50         assert(*r.first == 50);
     51         ++r.first;
     52         assert(*r.first == 50);
     53         ++r.first;
     54         assert(*r.first == 50);
     55     }
     56 #if __cplusplus >= 201103L
     57     {
     58         typedef std::unordered_multiset<int, std::hash<int>,
     59                                       std::equal_to<int>, min_allocator<int>> C;
     60         typedef C::iterator I;
     61         typedef int P;
     62         P a[] =
     63         {
     64             P(10),
     65             P(20),
     66             P(30),
     67             P(40),
     68             P(50),
     69             P(50),
     70             P(50),
     71             P(60),
     72             P(70),
     73             P(80)
     74         };
     75         C c(std::begin(a), std::end(a));
     76         std::pair<I, I> r = c.equal_range(30);
     77         assert(std::distance(r.first, r.second) == 1);
     78         assert(*r.first == 30);
     79         r = c.equal_range(5);
     80         assert(std::distance(r.first, r.second) == 0);
     81         r = c.equal_range(50);
     82         assert(std::distance(r.first, r.second) == 3);
     83         assert(*r.first == 50);
     84         ++r.first;
     85         assert(*r.first == 50);
     86         ++r.first;
     87         assert(*r.first == 50);
     88     }
     89 #endif
     90 }
     91