llvm-project
69 строк · 1.7 Кб
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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03, c++11, c++14
10
11// <map>
12
13// class map
14
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{
25std::size_t sz = c.size();26
27auto some_key = c.cbegin()->first;28
29for (auto first = c.cbegin(); first != c.cend();)30{31auto key_value = first->first;32typename Container::node_type t = c.extract(first++);33--sz;34assert(t.key() == key_value);35t.key() = some_key;36assert(t.key() == some_key);37assert(t.get_allocator() == c.get_allocator());38assert(sz == c.size());39}40
41assert(c.size() == 0);42}
43
44int main(int, char**)45{
46{47using map_type = std::map<int, int>;48map_type m = {{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};49test(m);50}51
52{53std::map<Counter<int>, Counter<int>> m =54{{1,1}, {2,2}, {3,3}, {4,4}, {5,5}, {6,6}};55assert(Counter_base::gConstructed == 12);56test(m);57assert(Counter_base::gConstructed == 0);58}59
60{61using min_alloc_map =62std::map<int, int, std::less<int>,63min_allocator<std::pair<const int, int>>>;64min_alloc_map m = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}};65test(m);66}67
68return 0;69}
70