]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/extract.cc
libstdc++: Ensure c++NN effective target present in all C++17 tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / modifiers / extract.cc
1 // Copyright (C) 2016-2020 Free Software Foundation, Inc.
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" }
19 // { dg-do run { target c++17 } }
20
21 #include <unordered_set>
22 #include <testsuite_hooks.h>
23
24 using test_type = std::unordered_multiset<int>;
25
26 void
27 test01()
28 {
29 test_type c{ 1, 1, 2, 2, 3, 3 };
30 test_type::node_type node;
31 test_type::iterator pos;
32
33 node = c.extract(0);
34 VERIFY( !node );
35 VERIFY( node.empty() );
36 VERIFY( c.size() == 6 );
37
38 pos = c.insert(std::move(node));
39 VERIFY( !node );
40 VERIFY( node.empty() );
41 VERIFY( c.size() == 6 );
42 VERIFY( pos == c.end() );
43
44 node = c.extract(1);
45 VERIFY( (bool)node );
46 VERIFY( !node.empty() );
47 VERIFY( c.size() == 5 );
48 VERIFY( node.get_allocator() == c.get_allocator() );
49 VERIFY( node.value() == 1 );
50
51 node.value() = 4;
52 VERIFY( node.value() == 4 );
53
54 pos = c.insert(std::move(node));
55 VERIFY( !node );
56 VERIFY( node.empty() );
57 VERIFY( c.size() == 6 );
58 VERIFY( pos != c.end() );
59 VERIFY( *pos == 4 );
60 VERIFY( c.count(1) == 1 );
61 VERIFY( c.count(4) == 1 );
62
63 pos = c.insert(c.begin(), std::move(node));
64 VERIFY( !node );
65 VERIFY( node.empty() );
66 VERIFY( c.size() == 6 );
67 VERIFY( pos == c.end() );
68
69 node = c.extract(1);
70 pos = c.insert(c.begin(), std::move(node));
71 VERIFY( !node );
72 VERIFY( c.size() == 6 );
73 VERIFY( pos != c.end() );
74 VERIFY( *pos == 1 );
75
76 test_type c2 = c;
77 node = c2.extract(1);
78 pos = c.insert(std::move(node));
79 VERIFY( pos != c.end() );
80 VERIFY( node.empty() );
81 VERIFY( *pos == 1 );
82 }
83
84 void
85 test02()
86 {
87 test_type c{ 1, 1, 2, 2, 3, 3 };
88 test_type::node_type node;
89 test_type::iterator pos;
90
91 const int val = *c.begin();
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() == val );
97
98 pos = c.insert(std::move(node));
99 VERIFY( node.empty() );
100 VERIFY( c.size() == 6 );
101 VERIFY( pos != c.end() );
102 VERIFY( *pos == val );
103 }
104
105 void
106 test03()
107 {
108 struct hash : std::hash<int> { };
109 struct equal : std::equal_to<int> { };
110 using std::is_same_v;
111 using compat_type1 = std::unordered_multiset<int, hash, equal>;
112 static_assert( is_same_v<test_type::node_type, compat_type1::node_type> );
113 using compat_type2 = std::unordered_set<int>;
114 static_assert( is_same_v<test_type::node_type, compat_type2::node_type> );
115 using compat_type3 = std::unordered_set<int, hash, equal>;
116 static_assert( is_same_v<test_type::node_type, compat_type3::node_type> );
117 }
118
119 int
120 main()
121 {
122 test01();
123 test02();
124 test03();
125 }