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 // UNSUPPORTED: c++98, c++03, c++11, c++14
     11 
     12 // <unordered_set>
     13 
     14 // class unordered_set
     15 
     16 // iterator insert(const_iterator hint, node_type&&);
     17 
     18 #include <unordered_set>
     19 #include "min_allocator.h"
     20 
     21 template <class Container>
     22 typename Container::node_type
     23 node_factory(typename Container::key_type const& key)
     24 {
     25     static Container c;
     26     auto p = c.insert(key);
     27     assert(p.second);
     28     return c.extract(p.first);
     29 }
     30 
     31 template <class Container>
     32 void test(Container& c)
     33 {
     34     auto* nf = &node_factory<Container>;
     35 
     36     for (int i = 0; i != 10; ++i)
     37     {
     38         typename Container::node_type node = nf(i);
     39         assert(!node.empty());
     40         size_t prev = c.size();
     41         auto it = c.insert(c.end(), std::move(node));
     42         assert(node.empty());
     43         assert(prev + 1 == c.size());
     44         assert(*it == i);
     45     }
     46 
     47     assert(c.size() == 10);
     48 
     49     for (int i = 0; i != 10; ++i)
     50     {
     51         assert(c.count(i) == 1);
     52     }
     53 }
     54 
     55 int main()
     56 {
     57     std::unordered_set<int> m;
     58     test(m);
     59     std::unordered_set<int, std::hash<int>, std::equal_to<int>, min_allocator<int>> m2;
     60     test(m2);
     61 }
     62