]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/set/modifiers/extract.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / modifiers / extract.cc
CommitLineData
fbd26352 1// Copyright (C) 2016-2019 Free Software Foundation, Inc.
67218f06 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" }
c796fa2c 19// { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
67218f06 20
21#include <set>
22#include <algorithm>
23#include <testsuite_hooks.h>
24
25using test_type = std::set<int>;
26
27void
28test01()
29{
67218f06 30 test_type c{ 1, 2, 3 };
31 test_type::node_type node;
32 test_type::insert_return_type ins;
33 test_type::iterator pos;
34
35 node = c.extract(0);
36 VERIFY( !node );
37 VERIFY( node.empty() );
38 VERIFY( c.size() == 3 );
39
40 ins = c.insert(std::move(node));
41 VERIFY( !node );
42 VERIFY( node.empty() );
43 VERIFY( c.size() == 3 );
44 VERIFY( !ins.inserted );
45 VERIFY( !ins.node );
46 VERIFY( ins.position == c.end() );
47
48 node = c.extract(1);
49 VERIFY( (bool)node );
50 VERIFY( !node.empty() );
51 VERIFY( c.size() == 2 );
52 VERIFY( node.get_allocator() == c.get_allocator() );
53 VERIFY( node.value() == 1 );
54
55 node.value() = 4;
56 VERIFY( node.value() == 4 );
57
58 ins = c.insert(std::move(node));
59 VERIFY( !node );
60 VERIFY( node.empty() );
61 VERIFY( c.size() == 3 );
62 VERIFY( ins.inserted );
63 VERIFY( !ins.node );
64 VERIFY( ins.position != c.end() );
65 VERIFY( *ins.position == 4 );
66 VERIFY( c.count(1) == 0 );
67 VERIFY( c.count(4) == 1 );
68 VERIFY( std::is_sorted(c.begin(), c.end()) );
69
70 pos = c.insert(c.begin(), std::move(node));
71 VERIFY( !node );
72 VERIFY( node.empty() );
73 VERIFY( c.size() == 3 );
74 VERIFY( pos == c.end() );
75
76 node = c.extract(2);
77 pos = c.insert(c.begin(), std::move(node));
78 VERIFY( c.size() == 3 );
79 VERIFY( pos != c.end() );
80 VERIFY( *pos == 2 );
81
82 test_type c2 = c;
83 node = c2.extract(3);
84 ins = c.insert(std::move(node));
85 VERIFY( node.empty() );
86 VERIFY( ins.position != c.end() );
87 VERIFY( !ins.inserted );
88 VERIFY( !ins.node.empty() );
89 VERIFY( ins.node.value() == 3 );
90 VERIFY( *ins.position == ins.node.value() );
91}
92
93void
94test02()
95{
67218f06 96 test_type c{ 1, 2, 3 };
97 test_type::node_type node;
98 test_type::insert_return_type ins;
99
100 node = c.extract(c.begin());
101 VERIFY( (bool)node );
102 VERIFY( !node.empty() );
103 VERIFY( c.size() == 2 );
104 VERIFY( node.get_allocator() == c.get_allocator() );
105 VERIFY( node.value() == 1 );
106
107 ins = c.insert(std::move(node));
108 VERIFY( node.empty() );
109 VERIFY( c.size() == 3 );
110 VERIFY( ins.inserted );
111 VERIFY( !ins.node );
112 VERIFY( ins.position != c.end() );
113 VERIFY( *ins.position == 1 );
114}
115
116void
117test03()
118{
119 struct less : std::less<int> { };
120 using std::is_same_v;
121 using compat_type1 = std::set<int, less>;
122 static_assert( is_same_v<test_type::node_type, compat_type1::node_type> );
123 using compat_type2 = std::multiset<int>;
124 static_assert( is_same_v<test_type::node_type, compat_type2::node_type> );
125 using compat_type3 = std::multiset<int, less>;
126 static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
127}
128
f5735855 129void
130test04()
131{
132 // Check order of members in insert_return_type
133 auto [pos, ins, node] = test_type::insert_return_type{};
134 using std::is_same_v;
135 static_assert( is_same_v<test_type::iterator, decltype(pos)> );
136 static_assert( is_same_v<bool, decltype(ins)> );
137 static_assert( is_same_v<test_type::node_type, decltype(node)> );
138}
139
67218f06 140int
141main()
142{
143 test01();
144 test02();
145 test03();
146}