Update copyright in libstdc++-v3.
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / vector / modifiers / swap / 2.cc
blob0361568e68502bf427bec3b18b8c4c2733e12fa3
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2013 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.
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 // 23.2.4.3 vector::swap
22 #include <vector>
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator as a non-empty allocator.
27 void
28 test01()
30 bool test __attribute__((unused)) = true;
31 using namespace std;
33 typedef __gnu_test::uneq_allocator<char> my_alloc;
34 typedef vector<char, my_alloc> my_vector;
36 const char title01[] = "Rivers of sand";
37 const char title02[] = "Concret PH";
38 const char title03[] = "Sonatas and Interludes for Prepared Piano";
39 const char title04[] = "never as tired as when i'm waking up";
41 const size_t N1 = sizeof(title01);
42 const size_t N2 = sizeof(title02);
43 const size_t N3 = sizeof(title03);
44 const size_t N4 = sizeof(title04);
46 my_vector::size_type size01, size02;
48 my_alloc alloc01(1);
50 my_vector vec01(alloc01);
51 size01 = vec01.size();
52 my_vector vec02(alloc01);
53 size02 = vec02.size();
55 vec01.swap(vec02);
56 VERIFY( vec01.size() == size02 );
57 VERIFY( vec01.empty() );
58 VERIFY( vec02.size() == size01 );
59 VERIFY( vec02.empty() );
61 my_vector vec03(alloc01);
62 size01 = vec03.size();
63 my_vector vec04(title02, title02 + N2, alloc01);
64 size02 = vec04.size();
66 vec03.swap(vec04);
67 VERIFY( vec03.size() == size02 );
68 VERIFY( equal(vec03.begin(), vec03.end(), title02) );
69 VERIFY( vec04.size() == size01 );
70 VERIFY( vec04.empty() );
72 my_vector vec05(title01, title01 + N1, alloc01);
73 size01 = vec05.size();
74 my_vector vec06(title02, title02 + N2, alloc01);
75 size02 = vec06.size();
77 vec05.swap(vec06);
78 VERIFY( vec05.size() == size02 );
79 VERIFY( equal(vec05.begin(), vec05.end(), title02) );
80 VERIFY( vec06.size() == size01 );
81 VERIFY( equal(vec06.begin(), vec06.end(), title01) );
83 my_vector vec07(title01, title01 + N1, alloc01);
84 size01 = vec07.size();
85 my_vector vec08(title03, title03 + N3, alloc01);
86 size02 = vec08.size();
88 vec07.swap(vec08);
89 VERIFY( vec07.size() == size02 );
90 VERIFY( equal(vec07.begin(), vec07.end(), title03) );
91 VERIFY( vec08.size() == size01 );
92 VERIFY( equal(vec08.begin(), vec08.end(), title01) );
94 my_vector vec09(title03, title03 + N3, alloc01);
95 size01 = vec09.size();
96 my_vector vec10(title04, title04 + N4, alloc01);
97 size02 = vec10.size();
99 vec09.swap(vec10);
100 VERIFY( vec09.size() == size02 );
101 VERIFY( equal(vec09.begin(), vec09.end(), title04) );
102 VERIFY( vec10.size() == size01 );
103 VERIFY( equal(vec10.begin(), vec10.end(), title03) );
105 my_vector vec11(title04, title04 + N4, alloc01);
106 size01 = vec11.size();
107 my_vector vec12(title01, title01 + N1, alloc01);
108 size02 = vec12.size();
110 vec11.swap(vec12);
111 VERIFY( vec11.size() == size02 );
112 VERIFY( equal(vec11.begin(), vec11.end(), title01) );
113 VERIFY( vec12.size() == size01 );
114 VERIFY( equal(vec12.begin(), vec12.end(), title04) );
116 my_vector vec13(title03, title03 + N3, alloc01);
117 size01 = vec13.size();
118 my_vector vec14(title03, title03 + N3, alloc01);
119 size02 = vec14.size();
121 vec13.swap(vec14);
122 VERIFY( vec13.size() == size02 );
123 VERIFY( equal(vec13.begin(), vec13.end(), title03) );
124 VERIFY( vec14.size() == size01 );
125 VERIFY( equal(vec14.begin(), vec14.end(), title03) );
128 int main()
130 test01();
131 return 0;