Merge from mainline
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / modifiers / swap / 2.cc
blobdc2c9c9080d920ae05ade6be8dbcfc9dfe76fcd9
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 // 23.3.2 multimap::swap
23 #include <map>
24 #include <testsuite_hooks.h>
25 #include <testsuite_allocator.h>
27 // uneq_allocator as a non-empty allocator.
28 void
29 test01()
31 bool test __attribute__((unused)) = true;
32 using namespace std;
34 typedef pair<const char, int> my_pair;
35 typedef __gnu_test::uneq_allocator<my_pair> my_alloc;
36 typedef multimap<char, int, less<char>, my_alloc> my_mmap;
38 const char title01[] = "Rivers of sand";
39 const char title02[] = "Concret PH";
40 const char title03[] = "Sonatas and Interludes for Prepared Piano";
41 const char title04[] = "never as tired as when i'm waking up";
43 const size_t N1 = sizeof(title01);
44 const size_t N2 = sizeof(title02);
45 const size_t N3 = sizeof(title03);
46 const size_t N4 = sizeof(title04);
48 multimap<char, int> mmap01_ref;
49 for (size_t i = 0; i < N1; ++i)
50 mmap01_ref.insert(my_pair(title01[i], i));
51 multimap<char, int> mmap02_ref;
52 for (size_t i = 0; i < N2; ++i)
53 mmap02_ref.insert(my_pair(title02[i], i));
54 multimap<char, int> mmap03_ref;
55 for (size_t i = 0; i < N3; ++i)
56 mmap03_ref.insert(my_pair(title03[i], i));
57 multimap<char, int> mmap04_ref;
58 for (size_t i = 0; i < N4; ++i)
59 mmap04_ref.insert(my_pair(title04[i], i));
61 my_mmap::size_type size01, size02;
63 my_alloc alloc01(1);
65 my_mmap mmap01(less<char>(), alloc01);
66 size01 = mmap01.size();
67 my_mmap mmap02(less<char>(), alloc01);
68 size02 = mmap02.size();
70 mmap01.swap(mmap02);
71 VERIFY( mmap01.size() == size02 );
72 VERIFY( mmap01.empty() );
73 VERIFY( mmap02.size() == size01 );
74 VERIFY( mmap02.empty() );
76 my_mmap mmap03(less<char>(), alloc01);
77 size01 = mmap03.size();
78 my_mmap mmap04(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01);
79 size02 = mmap04.size();
81 mmap03.swap(mmap04);
82 VERIFY( mmap03.size() == size02 );
83 VERIFY( equal(mmap03.begin(), mmap03.end(), mmap02_ref.begin()) );
84 VERIFY( mmap04.size() == size01 );
85 VERIFY( mmap04.empty() );
87 my_mmap mmap05(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
88 size01 = mmap05.size();
89 my_mmap mmap06(mmap02_ref.begin(), mmap02_ref.end(), less<char>(), alloc01);
90 size02 = mmap06.size();
92 mmap05.swap(mmap06);
93 VERIFY( mmap05.size() == size02 );
94 VERIFY( equal(mmap05.begin(), mmap05.end(), mmap02_ref.begin()) );
95 VERIFY( mmap06.size() == size01 );
96 VERIFY( equal(mmap06.begin(), mmap06.end(), mmap01_ref.begin()) );
98 my_mmap mmap07(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
99 size01 = mmap07.size();
100 my_mmap mmap08(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
101 size02 = mmap08.size();
103 mmap07.swap(mmap08);
104 VERIFY( mmap07.size() == size02 );
105 VERIFY( equal(mmap07.begin(), mmap07.end(), mmap03_ref.begin()) );
106 VERIFY( mmap08.size() == size01 );
107 VERIFY( equal(mmap08.begin(), mmap08.end(), mmap01_ref.begin()) );
109 my_mmap mmap09(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
110 size01 = mmap09.size();
111 my_mmap mmap10(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01);
112 size02 = mmap10.size();
114 mmap09.swap(mmap10);
115 VERIFY( mmap09.size() == size02 );
116 VERIFY( equal(mmap09.begin(), mmap09.end(), mmap04_ref.begin()) );
117 VERIFY( mmap10.size() == size01 );
118 VERIFY( equal(mmap10.begin(), mmap10.end(), mmap03_ref.begin()) );
120 my_mmap mmap11(mmap04_ref.begin(), mmap04_ref.end(), less<char>(), alloc01);
121 size01 = mmap11.size();
122 my_mmap mmap12(mmap01_ref.begin(), mmap01_ref.end(), less<char>(), alloc01);
123 size02 = mmap12.size();
125 mmap11.swap(mmap12);
126 VERIFY( mmap11.size() == size02 );
127 VERIFY( equal(mmap11.begin(), mmap11.end(), mmap01_ref.begin()) );
128 VERIFY( mmap12.size() == size01 );
129 VERIFY( equal(mmap12.begin(), mmap12.end(), mmap04_ref.begin()) );
131 my_mmap mmap13(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
132 size01 = mmap13.size();
133 my_mmap mmap14(mmap03_ref.begin(), mmap03_ref.end(), less<char>(), alloc01);
134 size02 = mmap14.size();
136 mmap13.swap(mmap14);
137 VERIFY( mmap13.size() == size02 );
138 VERIFY( equal(mmap13.begin(), mmap13.end(), mmap03_ref.begin()) );
139 VERIFY( mmap14.size() == size01 );
140 VERIFY( equal(mmap14.begin(), mmap14.end(), mmap03_ref.begin()) );
143 int main()
145 test01();
146 return 0;