1 // Copyright (C) 2016-2025 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++17 } }
22 #include <testsuite_hooks.h>
24 using test_type
= std::set
<int>;
29 test_type c
{ 1, 2, 3 };
30 test_type::node_type node
;
31 test_type::insert_return_type ins
;
32 test_type::iterator pos
;
36 VERIFY( node
.empty() );
37 VERIFY( c
.size() == 3 );
39 ins
= c
.insert(std::move(node
));
41 VERIFY( node
.empty() );
42 VERIFY( c
.size() == 3 );
43 VERIFY( !ins
.inserted
);
45 VERIFY( ins
.position
== c
.end() );
49 VERIFY( !node
.empty() );
50 VERIFY( c
.size() == 2 );
51 VERIFY( node
.get_allocator() == c
.get_allocator() );
52 VERIFY( node
.value() == 1 );
55 VERIFY( node
.value() == 4 );
57 ins
= c
.insert(std::move(node
));
59 VERIFY( node
.empty() );
60 VERIFY( c
.size() == 3 );
61 VERIFY( ins
.inserted
);
63 VERIFY( ins
.position
!= c
.end() );
64 VERIFY( *ins
.position
== 4 );
65 VERIFY( c
.count(1) == 0 );
66 VERIFY( c
.count(4) == 1 );
67 VERIFY( std::is_sorted(c
.begin(), c
.end()) );
69 pos
= c
.insert(c
.begin(), std::move(node
));
71 VERIFY( node
.empty() );
72 VERIFY( c
.size() == 3 );
73 VERIFY( pos
== c
.end() );
76 pos
= c
.insert(c
.begin(), std::move(node
));
77 VERIFY( c
.size() == 3 );
78 VERIFY( pos
!= c
.end() );
83 ins
= c
.insert(std::move(node
));
84 VERIFY( node
.empty() );
85 VERIFY( ins
.position
!= c
.end() );
86 VERIFY( !ins
.inserted
);
87 VERIFY( !ins
.node
.empty() );
88 VERIFY( ins
.node
.value() == 3 );
89 VERIFY( *ins
.position
== ins
.node
.value() );
95 test_type c
{ 1, 2, 3 };
96 test_type::node_type node
;
97 test_type::insert_return_type ins
;
99 node
= c
.extract(c
.begin());
100 VERIFY( (bool)node
);
101 VERIFY( !node
.empty() );
102 VERIFY( c
.size() == 2 );
103 VERIFY( node
.get_allocator() == c
.get_allocator() );
104 VERIFY( node
.value() == 1 );
106 ins
= c
.insert(std::move(node
));
107 VERIFY( node
.empty() );
108 VERIFY( c
.size() == 3 );
109 VERIFY( ins
.inserted
);
111 VERIFY( ins
.position
!= c
.end() );
112 VERIFY( *ins
.position
== 1 );
118 struct less
: std::less
<int> { };
119 using std::is_same_v
;
120 using compat_type1
= std::set
<int, less
>;
121 static_assert( is_same_v
<test_type::node_type
, compat_type1::node_type
> );
122 using compat_type2
= std::multiset
<int>;
123 static_assert( is_same_v
<test_type::node_type
, compat_type2::node_type
> );
124 using compat_type3
= std::multiset
<int, less
>;
125 static_assert( is_same_v
<test_type::node_type
, compat_type3::node_type
> );
131 // Check order of members in insert_return_type
132 auto [pos
, ins
, node
] = test_type::insert_return_type
{};
133 using std::is_same_v
;
134 static_assert( is_same_v
<test_type::iterator
, decltype(pos
)> );
135 static_assert( is_same_v
<bool, decltype(ins
)> );
136 static_assert( is_same_v
<test_type::node_type
, decltype(node
)> );