Merged with mainline at revision 128810.
[official-gcc.git] / libstdc++-v3 / testsuite / tr1 / 6_containers / unordered_set / swap / 1.cc
blob23d6f45c71cc0dd67a606d2f107578e3feda3c0e
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
21 // 6.3.4.3 unordered_set::swap
23 #include <tr1/unordered_set>
24 #include <set>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator as a non-empty allocator.
29 void
30 test01()
32 bool test __attribute__((unused)) = true;
33 using namespace std::tr1;
34 using std::equal_to;
35 using std::set;
37 typedef __gnu_test::uneq_allocator<char> my_alloc;
38 typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset;
40 const char title01[] = "Rivers of sand";
41 const char title02[] = "Concret PH";
42 const char title03[] = "Sonatas and Interludes for Prepared Piano";
43 const char title04[] = "never as tired as when i'm waking up";
45 const size_t N1 = sizeof(title01);
46 const size_t N2 = sizeof(title02);
47 const size_t N3 = sizeof(title03);
48 const size_t N4 = sizeof(title04);
50 typedef set<char> my_set;
51 const my_set set01_ref(title01, title01 + N1);
52 const my_set set02_ref(title02, title02 + N2);
53 const my_set set03_ref(title03, title03 + N3);
54 const my_set set04_ref(title04, title04 + N4);
56 my_uset::size_type size01, size02;
58 my_alloc alloc01(1);
60 my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01);
61 size01 = uset01.size();
62 my_uset uset02(10, hash<char>(), equal_to<char>(), alloc01);
63 size02 = uset02.size();
65 uset01.swap(uset02);
66 VERIFY( uset01.size() == size02 );
67 VERIFY( uset01.empty() );
68 VERIFY( uset02.size() == size01 );
69 VERIFY( uset02.empty() );
71 my_uset uset03(10, hash<char>(), equal_to<char>(), alloc01);
72 size01 = uset03.size();
73 my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
74 equal_to<char>(), alloc01);
75 size02 = uset04.size();
77 uset03.swap(uset04);
78 VERIFY( uset03.size() == size02 );
79 VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref );
80 VERIFY( uset04.size() == size01 );
81 VERIFY( uset04.empty() );
83 my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
84 equal_to<char>(), alloc01);
85 size01 = uset05.size();
86 my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
87 equal_to<char>(), alloc01);
88 size02 = uset06.size();
90 uset05.swap(uset06);
91 VERIFY( uset05.size() == size02 );
92 VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref );
93 VERIFY( uset06.size() == size01 );
94 VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref );
96 my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
97 equal_to<char>(), alloc01);
98 size01 = uset07.size();
99 my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
100 equal_to<char>(), alloc01);
101 size02 = uset08.size();
103 uset07.swap(uset08);
104 VERIFY( uset07.size() == size02 );
105 VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref );
106 VERIFY( uset08.size() == size01 );
107 VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref );
109 my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
110 equal_to<char>(), alloc01);
111 size01 = uset09.size();
112 my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
113 equal_to<char>(), alloc01);
114 size02 = uset10.size();
116 uset09.swap(uset10);
117 VERIFY( uset09.size() == size02 );
118 VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref );
119 VERIFY( uset10.size() == size01 );
120 VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref );
122 my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
123 equal_to<char>(), alloc01);
124 size01 = uset11.size();
125 my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
126 equal_to<char>(), alloc01);
127 size02 = uset12.size();
129 uset11.swap(uset12);
130 VERIFY( uset11.size() == size02 );
131 VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref );
132 VERIFY( uset12.size() == size01 );
133 VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref );
135 my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
136 equal_to<char>(), alloc01);
137 size01 = uset13.size();
138 my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
139 equal_to<char>(), alloc01);
140 size02 = uset14.size();
142 uset13.swap(uset14);
143 VERIFY( uset13.size() == size02 );
144 VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref );
145 VERIFY( uset14.size() == size01 );
146 VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref );
149 int main()
151 test01();
152 return 0;