]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/6_containers/unordered_map/swap/1.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2016 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 6.3.4.4 unordered_map::swap
22 #include <tr1/unordered_map>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator as a non-empty allocator.
31 bool test
__attribute__((unused
)) = true;
32 using namespace std::tr1
;
37 typedef pair
<const char, int> my_pair
;
38 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
39 typedef unordered_map
<char, int, hash
<char>, equal_to
<char>, my_alloc
>
42 const char title01
[] = "Rivers of sand";
43 const char title02
[] = "Concret PH";
44 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
45 const char title04
[] = "never as tired as when i'm waking up";
47 const size_t N1
= sizeof(title01
);
48 const size_t N2
= sizeof(title02
);
49 const size_t N3
= sizeof(title03
);
50 const size_t N4
= sizeof(title04
);
52 typedef map
<char, int> my_map
;
54 for (size_t i
= 0; i
< N1
; ++i
)
55 map01_ref
.insert(my_pair(title01
[i
], i
));
57 for (size_t i
= 0; i
< N2
; ++i
)
58 map02_ref
.insert(my_pair(title02
[i
], i
));
60 for (size_t i
= 0; i
< N3
; ++i
)
61 map03_ref
.insert(my_pair(title03
[i
], i
));
63 for (size_t i
= 0; i
< N4
; ++i
)
64 map04_ref
.insert(my_pair(title04
[i
], i
));
66 my_umap::size_type size01
, size02
;
70 my_umap
umap01(10, hash
<char>(), equal_to
<char>(), alloc01
);
71 size01
= umap01
.size();
72 my_umap
umap02(10, hash
<char>(), equal_to
<char>(), alloc01
);
73 size02
= umap02
.size();
76 VERIFY( umap01
.size() == size02
);
77 VERIFY( umap01
.empty() );
78 VERIFY( umap02
.size() == size01
);
79 VERIFY( umap02
.empty() );
81 my_umap
umap03(10, hash
<char>(), equal_to
<char>(), alloc01
);
82 size01
= umap03
.size();
83 my_umap
umap04(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
84 equal_to
<char>(), alloc01
);
85 size02
= umap04
.size();
88 VERIFY( umap03
.size() == size02
);
89 VERIFY( my_map(umap03
.begin(), umap03
.end()) == map02_ref
);
90 VERIFY( umap04
.size() == size01
);
91 VERIFY( umap04
.empty() );
93 my_umap
umap05(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
94 equal_to
<char>(), alloc01
);
95 size01
= umap05
.size();
96 my_umap
umap06(map02_ref
.begin(), map02_ref
.end(), 10, hash
<char>(),
97 equal_to
<char>(), alloc01
);
98 size02
= umap06
.size();
101 VERIFY( umap05
.size() == size02
);
102 VERIFY( my_map(umap05
.begin(), umap05
.end()) == map02_ref
);
103 VERIFY( umap06
.size() == size01
);
104 VERIFY( my_map(umap06
.begin(), umap06
.end()) == map01_ref
);
106 my_umap
umap07(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
107 equal_to
<char>(), alloc01
);
108 size01
= umap07
.size();
109 my_umap
umap08(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
110 equal_to
<char>(), alloc01
);
111 size02
= umap08
.size();
114 VERIFY( umap07
.size() == size02
);
115 VERIFY( my_map(umap07
.begin(), umap07
.end()) == map03_ref
);
116 VERIFY( umap08
.size() == size01
);
117 VERIFY( my_map(umap08
.begin(), umap08
.end()) == map01_ref
);
119 my_umap
umap09(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
120 equal_to
<char>(), alloc01
);
121 size01
= umap09
.size();
122 my_umap
umap10(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
123 equal_to
<char>(), alloc01
);
124 size02
= umap10
.size();
127 VERIFY( umap09
.size() == size02
);
128 VERIFY( my_map(umap09
.begin(), umap09
.end()) == map04_ref
);
129 VERIFY( umap10
.size() == size01
);
130 VERIFY( my_map(umap10
.begin(), umap10
.end()) == map03_ref
);
132 my_umap
umap11(map04_ref
.begin(), map04_ref
.end(), 10, hash
<char>(),
133 equal_to
<char>(), alloc01
);
134 size01
= umap11
.size();
135 my_umap
umap12(map01_ref
.begin(), map01_ref
.end(), 10, hash
<char>(),
136 equal_to
<char>(), alloc01
);
137 size02
= umap12
.size();
140 VERIFY( umap11
.size() == size02
);
141 VERIFY( my_map(umap11
.begin(), umap11
.end()) == map01_ref
);
142 VERIFY( umap12
.size() == size01
);
143 VERIFY( my_map(umap12
.begin(), umap12
.end()) == map04_ref
);
145 my_umap
umap13(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
146 equal_to
<char>(), alloc01
);
147 size01
= umap13
.size();
148 my_umap
umap14(map03_ref
.begin(), map03_ref
.end(), 10, hash
<char>(),
149 equal_to
<char>(), alloc01
);
150 size02
= umap14
.size();
153 VERIFY( umap13
.size() == size02
);
154 VERIFY( my_map(umap13
.begin(), umap13
.end()) == map03_ref
);
155 VERIFY( umap14
.size() == size01
);
156 VERIFY( my_map(umap14
.begin(), umap14
.end()) == map03_ref
);