]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_set/swap/1.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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,
21 // 6.3.4.3 unordered_set::swap
23 #include <tr1/unordered_set>
25 #include <testsuite_hooks.h>
26 #include <testsuite_allocator.h>
28 // uneq_allocator as a non-empty allocator.
32 bool test
__attribute__((unused
)) = true;
36 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
37 typedef unordered_set
<char, hash
<char>, equal_to
<char>, my_alloc
> my_uset
;
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";
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
);
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
);
55 my_uset::size_type size01
, size02
;
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();
65 VERIFY( uset01
.size() == size02
);
66 VERIFY( uset01
.empty() );
67 VERIFY( uset02
.size() == size01
);
68 VERIFY( uset02
.empty() );
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();
77 VERIFY( uset03
.size() == size02
);
78 VERIFY( my_set(uset03
.begin(), uset03
.end()) == set02_ref
);
79 VERIFY( uset04
.size() == size01
);
80 VERIFY( uset04
.empty() );
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();
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
);
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();
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
);
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();
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
);
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();
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
);
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();
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
);