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 |
|
|
// 23.3.1 map::swap
|
21 |
|
|
|
22 |
|
|
#include <map>
|
23 |
|
|
#include <testsuite_hooks.h>
|
24 |
|
|
#include <testsuite_allocator.h>
|
25 |
|
|
|
26 |
|
|
// uneq_allocator as a non-empty allocator.
|
27 |
|
|
void
|
28 |
|
|
test01()
|
29 |
|
|
{
|
30 |
|
|
bool test __attribute__((unused)) = true;
|
31 |
|
|
using namespace std;
|
32 |
|
|
|
33 |
|
|
typedef pair<const char, int> my_pair;
|
34 |
|
|
typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
|
35 |
|
|
typedef map<char, int, less<char>, my_alloc> my_map;
|
36 |
|
|
|
37 |
|
|
const char title01[] = "Rivers of sand";
|
38 |
|
|
const char title02[] = "Concret PH";
|
39 |
|
|
const char title03[] = "Sonatas and Interludes for Prepared Piano";
|
40 |
|
|
const char title04[] = "never as tired as when i'm waking up";
|
41 |
|
|
|
42 |
|
|
const size_t N1 = sizeof(title01);
|
43 |
|
|
const size_t N2 = sizeof(title02);
|
44 |
|
|
const size_t N3 = sizeof(title03);
|
45 |
|
|
const size_t N4 = sizeof(title04);
|
46 |
|
|
|
47 |
|
|
map<char, int> map01_ref;
|
48 |
|
|
for (size_t i = 0; i < N1; ++i)
|
49 |
|
|
map01_ref.insert(my_pair(title01[i], i));
|
50 |
|
|
map<char, int> map02_ref;
|
51 |
|
|
for (size_t i = 0; i < N2; ++i)
|
52 |
|
|
map02_ref.insert(my_pair(title02[i], i));
|
53 |
|
|
map<char, int> map03_ref;
|
54 |
|
|
for (size_t i = 0; i < N3; ++i)
|
55 |
|
|
map03_ref.insert(my_pair(title03[i], i));
|
56 |
|
|
map<char, int> map04_ref;
|
57 |
|
|
for (size_t i = 0; i < N4; ++i)
|
58 |
|
|
map04_ref.insert(my_pair(title04[i], i));
|
59 |
|
|
|
60 |
|
|
my_map::size_type size01, size02;
|
61 |
|
|
|
62 |
|
|
my_alloc alloc01(1);
|
63 |
|
|
|
64 |
|
|
my_map map01(less<char>(), alloc01);
|
65 |
|
|
size01 = map01.size();
|
66 |
|
|
my_map map02(less<char>(), alloc01);
|
67 |
|
|
size02 = map02.size();
|
68 |
|
|
|
69 |
|
|
map01.swap(map02);
|
70 |
|
|
VERIFY( map01.size() == size02 );
|
71 |
|
|
VERIFY( map01.empty() );
|
72 |
|
|
VERIFY( map02.size() == size01 );
|
73 |
|
|
VERIFY( map02.empty() );
|
74 |
|
|
|
75 |
|
|
my_map map03(less<char>(), alloc01);
|
76 |
|
|
size01 = map03.size();
|
77 |
|
|
my_map map04(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01);
|
78 |
|
|
size02 = map04.size();
|
79 |
|
|
|
80 |
|
|
map03.swap(map04);
|
81 |
|
|
VERIFY( map03.size() == size02 );
|
82 |
|
|
VERIFY( equal(map03.begin(), map03.end(), map02_ref.begin()) );
|
83 |
|
|
VERIFY( map04.size() == size01 );
|
84 |
|
|
VERIFY( map04.empty() );
|
85 |
|
|
|
86 |
|
|
my_map map05(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01);
|
87 |
|
|
size01 = map05.size();
|
88 |
|
|
my_map map06(map02_ref.begin(), map02_ref.end(), less<char>(), alloc01);
|
89 |
|
|
size02 = map06.size();
|
90 |
|
|
|
91 |
|
|
map05.swap(map06);
|
92 |
|
|
VERIFY( map05.size() == size02 );
|
93 |
|
|
VERIFY( equal(map05.begin(), map05.end(), map02_ref.begin()) );
|
94 |
|
|
VERIFY( map06.size() == size01 );
|
95 |
|
|
VERIFY( equal(map06.begin(), map06.end(), map01_ref.begin()) );
|
96 |
|
|
|
97 |
|
|
my_map map07(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01);
|
98 |
|
|
size01 = map07.size();
|
99 |
|
|
my_map map08(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
|
100 |
|
|
size02 = map08.size();
|
101 |
|
|
|
102 |
|
|
map07.swap(map08);
|
103 |
|
|
VERIFY( map07.size() == size02 );
|
104 |
|
|
VERIFY( equal(map07.begin(), map07.end(), map03_ref.begin()) );
|
105 |
|
|
VERIFY( map08.size() == size01 );
|
106 |
|
|
VERIFY( equal(map08.begin(), map08.end(), map01_ref.begin()) );
|
107 |
|
|
|
108 |
|
|
my_map map09(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
|
109 |
|
|
size01 = map09.size();
|
110 |
|
|
my_map map10(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01);
|
111 |
|
|
size02 = map10.size();
|
112 |
|
|
|
113 |
|
|
map09.swap(map10);
|
114 |
|
|
VERIFY( map09.size() == size02 );
|
115 |
|
|
VERIFY( equal(map09.begin(), map09.end(), map04_ref.begin()) );
|
116 |
|
|
VERIFY( map10.size() == size01 );
|
117 |
|
|
VERIFY( equal(map10.begin(), map10.end(), map03_ref.begin()) );
|
118 |
|
|
|
119 |
|
|
my_map map11(map04_ref.begin(), map04_ref.end(), less<char>(), alloc01);
|
120 |
|
|
size01 = map11.size();
|
121 |
|
|
my_map map12(map01_ref.begin(), map01_ref.end(), less<char>(), alloc01);
|
122 |
|
|
size02 = map12.size();
|
123 |
|
|
|
124 |
|
|
map11.swap(map12);
|
125 |
|
|
VERIFY( map11.size() == size02 );
|
126 |
|
|
VERIFY( equal(map11.begin(), map11.end(), map01_ref.begin()) );
|
127 |
|
|
VERIFY( map12.size() == size01 );
|
128 |
|
|
VERIFY( equal(map12.begin(), map12.end(), map04_ref.begin()) );
|
129 |
|
|
|
130 |
|
|
my_map map13(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
|
131 |
|
|
size01 = map13.size();
|
132 |
|
|
my_map map14(map03_ref.begin(), map03_ref.end(), less<char>(), alloc01);
|
133 |
|
|
size02 = map14.size();
|
134 |
|
|
|
135 |
|
|
map13.swap(map14);
|
136 |
|
|
VERIFY( map13.size() == size02 );
|
137 |
|
|
VERIFY( equal(map13.begin(), map13.end(), map03_ref.begin()) );
|
138 |
|
|
VERIFY( map14.size() == size01 );
|
139 |
|
|
VERIFY( equal(map14.begin(), map14.end(), map03_ref.begin()) );
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
int main()
|
143 |
|
|
{
|
144 |
|
|
test01();
|
145 |
|
|
return 0;
|
146 |
|
|
}
|