Home | History | Annotate | Download | only in multimap.modifiers
      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 // <map>
     13 
     14 // class multimap
     15 
     16 // node_type extract(const_iterator);
     17 
     18 #include <map>
     19 #include "min_allocator.h"
     20 #include "Counter.h"
     21 
     22 template <class Container>
     23 void test(Container& c)
     24 {
     25     size_t sz = c.size();
     26 
     27     auto some_key = c.cbegin()->first;
     28 
     29     for (auto first = c.cbegin(); first != c.cend();)
     30     {
     31         auto key_value = first->first;
     32         typename Container::node_type t = c.extract(first++);
     33         --sz;
     34         assert(t.key() == key_value);
     35         t.key() = some_key;
     36         assert(t.key() == some_key);
     37         assert(t.get_allocator() == c.get_allocator());
     38         assert(sz == c.size());
     39     }
     40 
     41     assert(c.size() == 0);
     42 }
     43 
     44 int main()
     45 {
     46     {
     47         using map_type = std::multimap<int, int>;
     48         map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};
     49         test(m);
     50     }
     51 
     52     {
     53         std::multimap<Counter<int>, Counter<int>> m =
     54             {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};
     55         assert(Counter_base::gConstructed == 12);
     56         test(m);
     57         assert(Counter_base::gConstructed == 0);
     58     }
     59 
     60     {
     61         using min_alloc_map =
     62             std::multimap<int, int, std::less<int>,
     63                      min_allocator<std::pair<const int, int>>>;
     64         min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};
     65         test(m);
     66     }
     67 }
     68