]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/6_containers/unordered_set/swap/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_set / swap / 1.cc
CommitLineData
f7ace77f
PC
1// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
2
83ffe9cd 3// Copyright (C) 2005-2023 Free Software Foundation, Inc.
f7ace77f
PC
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
f7ace77f
PC
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
f7ace77f
PC
19
20// 6.3.4.3 unordered_set::swap
21
22#include <tr1/unordered_set>
23#include <set>
24#include <testsuite_hooks.h>
25#include <testsuite_allocator.h>
26
27// uneq_allocator as a non-empty allocator.
28void
29test01()
30{
2df6377e
DG
31 using namespace std::tr1;
32 using std::equal_to;
33 using std::set;
f7ace77f
PC
34
35 typedef __gnu_test::uneq_allocator<char> my_alloc;
36 typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset;
37
38 const char title01[] = "Rivers of sand";
39 const char title02[] = "Concret PH";
40 const char title03[] = "Sonatas and Interludes for Prepared Piano";
41 const char title04[] = "never as tired as when i'm waking up";
42
43 const size_t N1 = sizeof(title01);
44 const size_t N2 = sizeof(title02);
45 const size_t N3 = sizeof(title03);
46 const size_t N4 = sizeof(title04);
47
48 typedef set<char> my_set;
49 const my_set set01_ref(title01, title01 + N1);
50 const my_set set02_ref(title02, title02 + N2);
51 const my_set set03_ref(title03, title03 + N3);
52 const my_set set04_ref(title04, title04 + N4);
53
54 my_uset::size_type size01, size02;
55
56 my_alloc alloc01(1);
57
58 my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01);
59 size01 = uset01.size();
60 my_uset uset02(10, hash<char>(), equal_to<char>(), alloc01);
61 size02 = uset02.size();
f92ab29f 62
f7ace77f
PC
63 uset01.swap(uset02);
64 VERIFY( uset01.size() == size02 );
65 VERIFY( uset01.empty() );
66 VERIFY( uset02.size() == size01 );
67 VERIFY( uset02.empty() );
68
69 my_uset uset03(10, hash<char>(), equal_to<char>(), alloc01);
70 size01 = uset03.size();
71 my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
72 equal_to<char>(), alloc01);
73 size02 = uset04.size();
f92ab29f 74
f7ace77f
PC
75 uset03.swap(uset04);
76 VERIFY( uset03.size() == size02 );
77 VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref );
78 VERIFY( uset04.size() == size01 );
79 VERIFY( uset04.empty() );
f92ab29f 80
f7ace77f
PC
81 my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
82 equal_to<char>(), alloc01);
83 size01 = uset05.size();
84 my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
85 equal_to<char>(), alloc01);
86 size02 = uset06.size();
f92ab29f 87
f7ace77f
PC
88 uset05.swap(uset06);
89 VERIFY( uset05.size() == size02 );
90 VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref );
91 VERIFY( uset06.size() == size01 );
92 VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref );
93
94 my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
95 equal_to<char>(), alloc01);
96 size01 = uset07.size();
97 my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
98 equal_to<char>(), alloc01);
99 size02 = uset08.size();
100
101 uset07.swap(uset08);
102 VERIFY( uset07.size() == size02 );
103 VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref );
104 VERIFY( uset08.size() == size01 );
105 VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref );
106
107 my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
108 equal_to<char>(), alloc01);
109 size01 = uset09.size();
110 my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
111 equal_to<char>(), alloc01);
112 size02 = uset10.size();
113
114 uset09.swap(uset10);
115 VERIFY( uset09.size() == size02 );
116 VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref );
117 VERIFY( uset10.size() == size01 );
118 VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref );
119
120 my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
121 equal_to<char>(), alloc01);
122 size01 = uset11.size();
123 my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
124 equal_to<char>(), alloc01);
125 size02 = uset12.size();
126
127 uset11.swap(uset12);
128 VERIFY( uset11.size() == size02 );
129 VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref );
130 VERIFY( uset12.size() == size01 );
131 VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref );
132
133 my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
134 equal_to<char>(), alloc01);
135 size01 = uset13.size();
136 my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
137 equal_to<char>(), alloc01);
138 size02 = uset14.size();
139
140 uset13.swap(uset14);
141 VERIFY( uset13.size() == size02 );
142 VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref );
143 VERIFY( uset14.size() == size01 );
144 VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref );
145}
146
147int main()
f92ab29f 148{
f7ace77f
PC
149 test01();
150 return 0;
151}