1 // Copyright (C) 2016-2017 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-options "-std=gnu++17" }
19 // { dg-skip-if "" { *-*-* } { "-D_GLIBCXX_PROFILE" } }
23 #include <testsuite_hooks.h>
25 using test_type
= std::set
<int>;
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
;
37 VERIFY( node
.empty() );
38 VERIFY( c
.size() == 3 );
40 ins
= c
.insert(std::move(node
));
42 VERIFY( node
.empty() );
43 VERIFY( c
.size() == 3 );
44 VERIFY( !ins
.inserted
);
46 VERIFY( ins
.position
== c
.end() );
50 VERIFY( !node
.empty() );
51 VERIFY( c
.size() == 2 );
52 VERIFY( node
.get_allocator() == c
.get_allocator() );
53 VERIFY( node
.value() == 1 );
56 VERIFY( node
.value() == 4 );
58 ins
= c
.insert(std::move(node
));
60 VERIFY( node
.empty() );
61 VERIFY( c
.size() == 3 );
62 VERIFY( ins
.inserted
);
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()) );
70 pos
= c
.insert(c
.begin(), std::move(node
));
72 VERIFY( node
.empty() );
73 VERIFY( c
.size() == 3 );
74 VERIFY( pos
== c
.end() );
77 pos
= c
.insert(c
.begin(), std::move(node
));
78 VERIFY( c
.size() == 3 );
79 VERIFY( pos
!= c
.end() );
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() );
96 test_type c
{ 1, 2, 3 };
97 test_type::node_type node
;
98 test_type::insert_return_type ins
;
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 );
107 ins
= c
.insert(std::move(node
));
108 VERIFY( node
.empty() );
109 VERIFY( c
.size() == 3 );
110 VERIFY( ins
.inserted
);
112 VERIFY( ins
.position
!= c
.end() );
113 VERIFY( *ins
.position
== 1 );
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
> );
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
)> );