Home | History | Annotate | Download | only in unord.set
      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_set
     15 
     16 // void reserve(size_type n);
     17 
     18 #include <unordered_set>
     19 #include <cassert>
     20 
     21 #include "min_allocator.h"
     22 
     23 template <class C>
     24 void test(const C& c)
     25 {
     26     assert(c.size() == 4);
     27     assert(c.count(1) == 1);
     28     assert(c.count(2) == 1);
     29     assert(c.count(3) == 1);
     30     assert(c.count(4) == 1);
     31 }
     32 
     33 int main()
     34 {
     35     {
     36         typedef std::unordered_set<int> C;
     37         typedef int P;
     38         P a[] =
     39         {
     40             P(1),
     41             P(2),
     42             P(3),
     43             P(4),
     44             P(1),
     45             P(2)
     46         };
     47         C c(a, a + sizeof(a)/sizeof(a[0]));
     48         test(c);
     49         assert(c.bucket_count() >= 5);
     50         c.reserve(3);
     51         assert(c.bucket_count() == 5);
     52         test(c);
     53         c.max_load_factor(2);
     54         c.reserve(3);
     55         assert(c.bucket_count() >= 2);
     56         test(c);
     57         c.reserve(31);
     58         assert(c.bucket_count() >= 16);
     59         test(c);
     60     }
     61 #if __cplusplus >= 201103L
     62     {
     63         typedef std::unordered_set<int, std::hash<int>,
     64                                       std::equal_to<int>, min_allocator<int>> C;
     65         typedef int P;
     66         P a[] =
     67         {
     68             P(1),
     69             P(2),
     70             P(3),
     71             P(4),
     72             P(1),
     73             P(2)
     74         };
     75         C c(a, a + sizeof(a)/sizeof(a[0]));
     76         test(c);
     77         assert(c.bucket_count() >= 5);
     78         c.reserve(3);
     79         assert(c.bucket_count() == 5);
     80         test(c);
     81         c.max_load_factor(2);
     82         c.reserve(3);
     83         assert(c.bucket_count() >= 2);
     84         test(c);
     85         c.reserve(31);
     86         assert(c.bucket_count() >= 16);
     87         test(c);
     88     }
     89 #endif
     90 }
     91