1 |
424 |
jeremybenn |
// 2005-12-20 Paolo Carlini <pcarlini@suse.de>
|
2 |
|
|
|
3 |
|
|
// Copyright (C) 2005, 2009 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 3, or (at your option)
|
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
|
17 |
|
|
// with this library; see the file COPYING3. If not see
|
18 |
|
|
// <http://www.gnu.org/licenses/>.
|
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.
|
28 |
|
|
void
|
29 |
|
|
test01()
|
30 |
|
|
{
|
31 |
|
|
bool test __attribute__((unused)) = true;
|
32 |
|
|
using namespace std::tr1;
|
33 |
|
|
using std::equal_to;
|
34 |
|
|
using std::set;
|
35 |
|
|
|
36 |
|
|
typedef __gnu_test::uneq_allocator<char> my_alloc;
|
37 |
|
|
typedef unordered_set<char, hash<char>, equal_to<char>, my_alloc> my_uset;
|
38 |
|
|
|
39 |
|
|
const char title01[] = "Rivers of sand";
|
40 |
|
|
const char title02[] = "Concret PH";
|
41 |
|
|
const char title03[] = "Sonatas and Interludes for Prepared Piano";
|
42 |
|
|
const char title04[] = "never as tired as when i'm waking up";
|
43 |
|
|
|
44 |
|
|
const size_t N1 = sizeof(title01);
|
45 |
|
|
const size_t N2 = sizeof(title02);
|
46 |
|
|
const size_t N3 = sizeof(title03);
|
47 |
|
|
const size_t N4 = sizeof(title04);
|
48 |
|
|
|
49 |
|
|
typedef set<char> my_set;
|
50 |
|
|
const my_set set01_ref(title01, title01 + N1);
|
51 |
|
|
const my_set set02_ref(title02, title02 + N2);
|
52 |
|
|
const my_set set03_ref(title03, title03 + N3);
|
53 |
|
|
const my_set set04_ref(title04, title04 + N4);
|
54 |
|
|
|
55 |
|
|
my_uset::size_type size01, size02;
|
56 |
|
|
|
57 |
|
|
my_alloc alloc01(1);
|
58 |
|
|
|
59 |
|
|
my_uset uset01(10, hash<char>(), equal_to<char>(), alloc01);
|
60 |
|
|
size01 = uset01.size();
|
61 |
|
|
my_uset uset02(10, hash<char>(), equal_to<char>(), alloc01);
|
62 |
|
|
size02 = uset02.size();
|
63 |
|
|
|
64 |
|
|
uset01.swap(uset02);
|
65 |
|
|
VERIFY( uset01.size() == size02 );
|
66 |
|
|
VERIFY( uset01.empty() );
|
67 |
|
|
VERIFY( uset02.size() == size01 );
|
68 |
|
|
VERIFY( uset02.empty() );
|
69 |
|
|
|
70 |
|
|
my_uset uset03(10, hash<char>(), equal_to<char>(), alloc01);
|
71 |
|
|
size01 = uset03.size();
|
72 |
|
|
my_uset uset04(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
|
73 |
|
|
equal_to<char>(), alloc01);
|
74 |
|
|
size02 = uset04.size();
|
75 |
|
|
|
76 |
|
|
uset03.swap(uset04);
|
77 |
|
|
VERIFY( uset03.size() == size02 );
|
78 |
|
|
VERIFY( my_set(uset03.begin(), uset03.end()) == set02_ref );
|
79 |
|
|
VERIFY( uset04.size() == size01 );
|
80 |
|
|
VERIFY( uset04.empty() );
|
81 |
|
|
|
82 |
|
|
my_uset uset05(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
|
83 |
|
|
equal_to<char>(), alloc01);
|
84 |
|
|
size01 = uset05.size();
|
85 |
|
|
my_uset uset06(set02_ref.begin(), set02_ref.end(), 10, hash<char>(),
|
86 |
|
|
equal_to<char>(), alloc01);
|
87 |
|
|
size02 = uset06.size();
|
88 |
|
|
|
89 |
|
|
uset05.swap(uset06);
|
90 |
|
|
VERIFY( uset05.size() == size02 );
|
91 |
|
|
VERIFY( my_set(uset05.begin(), uset05.end()) == set02_ref );
|
92 |
|
|
VERIFY( uset06.size() == size01 );
|
93 |
|
|
VERIFY( my_set(uset06.begin(), uset06.end()) == set01_ref );
|
94 |
|
|
|
95 |
|
|
my_uset uset07(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
|
96 |
|
|
equal_to<char>(), alloc01);
|
97 |
|
|
size01 = uset07.size();
|
98 |
|
|
my_uset uset08(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
|
99 |
|
|
equal_to<char>(), alloc01);
|
100 |
|
|
size02 = uset08.size();
|
101 |
|
|
|
102 |
|
|
uset07.swap(uset08);
|
103 |
|
|
VERIFY( uset07.size() == size02 );
|
104 |
|
|
VERIFY( my_set(uset07.begin(), uset07.end()) == set03_ref );
|
105 |
|
|
VERIFY( uset08.size() == size01 );
|
106 |
|
|
VERIFY( my_set(uset08.begin(), uset08.end()) == set01_ref );
|
107 |
|
|
|
108 |
|
|
my_uset uset09(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
|
109 |
|
|
equal_to<char>(), alloc01);
|
110 |
|
|
size01 = uset09.size();
|
111 |
|
|
my_uset uset10(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
|
112 |
|
|
equal_to<char>(), alloc01);
|
113 |
|
|
size02 = uset10.size();
|
114 |
|
|
|
115 |
|
|
uset09.swap(uset10);
|
116 |
|
|
VERIFY( uset09.size() == size02 );
|
117 |
|
|
VERIFY( my_set(uset09.begin(), uset09.end()) == set04_ref );
|
118 |
|
|
VERIFY( uset10.size() == size01 );
|
119 |
|
|
VERIFY( my_set(uset10.begin(), uset10.end()) == set03_ref );
|
120 |
|
|
|
121 |
|
|
my_uset uset11(set04_ref.begin(), set04_ref.end(), 10, hash<char>(),
|
122 |
|
|
equal_to<char>(), alloc01);
|
123 |
|
|
size01 = uset11.size();
|
124 |
|
|
my_uset uset12(set01_ref.begin(), set01_ref.end(), 10, hash<char>(),
|
125 |
|
|
equal_to<char>(), alloc01);
|
126 |
|
|
size02 = uset12.size();
|
127 |
|
|
|
128 |
|
|
uset11.swap(uset12);
|
129 |
|
|
VERIFY( uset11.size() == size02 );
|
130 |
|
|
VERIFY( my_set(uset11.begin(), uset11.end()) == set01_ref );
|
131 |
|
|
VERIFY( uset12.size() == size01 );
|
132 |
|
|
VERIFY( my_set(uset12.begin(), uset12.end()) == set04_ref );
|
133 |
|
|
|
134 |
|
|
my_uset uset13(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
|
135 |
|
|
equal_to<char>(), alloc01);
|
136 |
|
|
size01 = uset13.size();
|
137 |
|
|
my_uset uset14(set03_ref.begin(), set03_ref.end(), 10, hash<char>(),
|
138 |
|
|
equal_to<char>(), alloc01);
|
139 |
|
|
size02 = uset14.size();
|
140 |
|
|
|
141 |
|
|
uset13.swap(uset14);
|
142 |
|
|
VERIFY( uset13.size() == size02 );
|
143 |
|
|
VERIFY( my_set(uset13.begin(), uset13.end()) == set03_ref );
|
144 |
|
|
VERIFY( uset14.size() == size01 );
|
145 |
|
|
VERIFY( my_set(uset14.begin(), uset14.end()) == set03_ref );
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
int main()
|
149 |
|
|
{
|
150 |
|
|
test01();
|
151 |
|
|
return 0;
|
152 |
|
|
}
|