]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multiset/modifiers/extract.cc
1 // Copyright (C) 2016-2024 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::multiset
<int>;
29 test_type c
{ 1, 1, 2, 2, 3, 3 };
30 test_type::node_type node
;
31 test_type::iterator pos
;
35 VERIFY( node
.empty() );
36 VERIFY( c
.size() == 6 );
38 pos
= c
.insert(std::move(node
));
40 VERIFY( node
.empty() );
41 VERIFY( c
.size() == 6 );
42 VERIFY( pos
== c
.end() );
46 VERIFY( !node
.empty() );
47 VERIFY( c
.size() == 5 );
48 VERIFY( node
.get_allocator() == c
.get_allocator() );
49 VERIFY( node
.value() == 1 );
52 VERIFY( node
.value() == 4 );
54 pos
= c
.insert(std::move(node
));
56 VERIFY( node
.empty() );
57 VERIFY( c
.size() == 6 );
58 VERIFY( pos
!= c
.end() );
60 VERIFY( c
.count(1) == 1 );
61 VERIFY( c
.count(4) == 1 );
62 VERIFY( std::is_sorted(c
.begin(), c
.end()) );
64 pos
= c
.insert(c
.begin(), std::move(node
));
66 VERIFY( node
.empty() );
67 VERIFY( c
.size() == 6 );
68 VERIFY( pos
== c
.end() );
71 pos
= c
.insert(c
.begin(), std::move(node
));
73 VERIFY( c
.size() == 6 );
74 VERIFY( pos
!= c
.end() );
79 pos
= c
.insert(std::move(node
));
80 VERIFY( pos
!= c
.end() );
81 VERIFY( node
.empty() );
88 test_type c
{ 1, 1, 2, 2, 3, 3 };
89 test_type::node_type node
;
90 test_type::iterator pos
;
92 node
= c
.extract(c
.begin());
93 VERIFY( !node
.empty() );
94 VERIFY( c
.size() == 5 );
95 VERIFY( node
.get_allocator() == c
.get_allocator() );
96 VERIFY( node
.value() == 1 );
98 pos
= c
.insert(std::next(c
.begin()), std::move(node
));
99 VERIFY( node
.empty() );
100 VERIFY( c
.size() == 6 );
101 VERIFY( pos
!= c
.end() );
103 VERIFY( pos
== std::next(c
.begin()) );
109 struct less
: std::less
<int> { };
110 using std::is_same_v
;
111 using compat_type1
= std::multiset
<int, less
>;
112 static_assert( is_same_v
<test_type::node_type
, compat_type1::node_type
> );
113 using compat_type2
= std::set
<int>;
114 static_assert( is_same_v
<test_type::node_type
, compat_type2::node_type
> );
115 using compat_type3
= std::set
<int, less
>;
116 static_assert( is_same_v
<test_type::node_type
, compat_type3::node_type
> );