brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · 85beba3 Raw
64 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++1410 11// <map>12 13// class multimap14 15// node_type extract(const_iterator);16 17#include <map>18#include "test_macros.h"19#include "min_allocator.h"20#include "Counter.h"21 22template <class Container>23void test(Container& c) {24  std::size_t sz = c.size();25 26  auto some_key = c.cbegin()->first;27 28  for (auto first = c.cbegin(); first != c.cend();) {29    auto key_value                  = first->first;30    typename Container::node_type t = c.extract(first++);31    --sz;32    assert(t.key() == key_value);33    t.key() = some_key;34    assert(t.key() == some_key);35    assert(t.get_allocator() == c.get_allocator());36    assert(sz == c.size());37  }38 39  assert(c.size() == 0);40}41 42int main(int, char**) {43  {44    using map_type = std::multimap<int, int>;45    map_type m     = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};46    test(m);47  }48 49  {50    std::multimap<Counter<int>, Counter<int>> m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};51    assert(Counter_base::gConstructed == 12);52    test(m);53    assert(Counter_base::gConstructed == 0);54  }55 56  {57    using min_alloc_map = std::multimap<int, int, std::less<int>, min_allocator<std::pair<const int, int>>>;58    min_alloc_map m     = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};59    test(m);60  }61 62  return 0;63}64