]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multimap/modifiers/extract.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / modifiers / extract.cc
CommitLineData
a5544970 1// Copyright (C) 2016-2019 Free Software Foundation, Inc.
2dbe56bd
JW
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++17" }
ac4664f9 19// { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
2dbe56bd
JW
20
21#include <map>
22#include <algorithm>
23#include <testsuite_hooks.h>
24
25using test_type = std::multimap<int, int>;
26
27void
28test01()
29{
2dbe56bd
JW
30 test_type c{ {1, 10}, { 1, 11 }, {2, 20}, { 2, 21}, {3, 30}, { 3, 31 } };
31 test_type::node_type node;
32 test_type::iterator pos;
33
34 node = c.extract(0);
35 VERIFY( !node );
36 VERIFY( node.empty() );
37 VERIFY( c.size() == 6 );
38
39 pos = c.insert(std::move(node));
40 VERIFY( !node );
41 VERIFY( node.empty() );
42 VERIFY( c.size() == 6 );
43 VERIFY( pos == c.end() );
44
45 node = c.extract(1);
46 VERIFY( (bool)node );
47 VERIFY( !node.empty() );
48 VERIFY( c.size() == 5 );
49 VERIFY( c.count(1) == 1 );
50 VERIFY( node.get_allocator() == c.get_allocator() );
51 VERIFY( node.key() == 1 );
52 int mapped = node.mapped();
53 VERIFY( mapped == 10 || mapped == 11 );
54
55 node.key() = 4;
56 node.mapped() = 40;
57 VERIFY( node.key() == 4 );
58 VERIFY( node.mapped() == 40 );
59
60 pos = c.insert(std::move(node));
61 VERIFY( !node );
62 VERIFY( node.empty() );
63 VERIFY( c.size() == 6 );
64 VERIFY( pos != c.end() );
65 VERIFY( pos->first == 4 );
66 VERIFY( pos->second == 40 );
67 VERIFY( c.count(1) == 1 );
68 VERIFY( c.count(4) == 1 );
69 VERIFY( std::is_sorted(c.begin(), c.end()) );
70
71 pos = c.insert(c.begin(), std::move(node));
72 VERIFY( !node );
73 VERIFY( node.empty() );
74 VERIFY( c.size() == 6 );
75 VERIFY( pos == c.end() );
76
77 node = c.extract(1);
78 mapped = node.mapped();
79 pos = c.insert(c.begin(), std::move(node));
80 VERIFY( !node );
81 VERIFY( c.size() == 6 );
82 VERIFY( pos != c.end() );
83 VERIFY( pos->first == 1 );
84 VERIFY( pos->second == mapped );
85
86 test_type c2 = c;
87 node = c2.extract(1);
88 mapped = node.mapped();
89 pos = c.insert(std::move(node));
90 VERIFY( pos != c.end() );
91 VERIFY( node.empty() );
92 VERIFY( pos->first == 1 );
93 VERIFY( pos->second == mapped );
94}
95
96void
97test02()
98{
2dbe56bd
JW
99 test_type c{ {1, 10}, { 1, 11 }, {2, 20}, { 2, 21}, {3, 30}, { 3, 31 } };
100 test_type::node_type node;
101 test_type::iterator pos;
102
103 node = c.extract(c.begin());
104 VERIFY( !node.empty() );
105 VERIFY( c.size() == 5 );
106 VERIFY( node.get_allocator() == c.get_allocator() );
107 VERIFY( node.key() == 1 );
108 VERIFY( node.mapped() == 10 );
109
110 pos = c.insert(std::next(c.begin()), std::move(node));
111 VERIFY( node.empty() );
112 VERIFY( c.size() == 6 );
113 VERIFY( pos != c.end() );
114 VERIFY( pos->first == 1 );
115 VERIFY( pos->second == 10 );
116 VERIFY( pos == std::next(c.begin()) );
117}
118
119void
120test03()
121{
122 struct less : std::less<int> { };
123 using std::is_same_v;
124 using compat_type1 = std::multimap<int, int, less>;
125 static_assert( is_same_v<test_type::node_type, compat_type1::node_type> );
126 using compat_type2 = std::map<int, int>;
127 static_assert( is_same_v<test_type::node_type, compat_type2::node_type> );
128 using compat_type3 = std::map<int, int, less>;
129 static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
130}
131
132int
133main()
134{
135 test01();
136 test02();
137 test03();
138}