brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 2d7b6e5 Raw
60 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// <set>12 13// class set14 15// node_type extract(const_iterator);16 17#include <set>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  for (auto first = c.cbegin(); first != c.cend();) {27    auto key_value                  = *first;28    typename Container::node_type t = c.extract(first++);29    --sz;30    assert(t.value() == key_value);31    assert(t.get_allocator() == c.get_allocator());32    assert(sz == c.size());33  }34 35  assert(c.size() == 0);36}37 38int main(int, char**) {39  {40    using set_type = std::set<int>;41    set_type m     = {1, 2, 3, 4, 5, 6};42    test(m);43  }44 45  {46    std::set<Counter<int>> m = {1, 2, 3, 4, 5, 6};47    assert(Counter_base::gConstructed == 6);48    test(m);49    assert(Counter_base::gConstructed == 0);50  }51 52  {53    using min_alloc_set = std::set<int, std::less<int>, min_allocator<int>>;54    min_alloc_set m     = {1, 2, 3, 4, 5, 6};55    test(m);56  }57 58  return 0;59}60