]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/map/modifiers/swap/2.cc
1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2019 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/>.
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator as a non-empty allocator.
32 typedef pair
<const char, int> my_pair
;
33 typedef __gnu_test::uneq_allocator
<my_pair
> my_alloc
;
34 typedef map
<char, int, less
<char>, my_alloc
> my_map
;
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 map
<char, int> map01_ref
;
47 for (size_t i
= 0; i
< N1
; ++i
)
48 map01_ref
.insert(my_pair(title01
[i
], i
));
49 map
<char, int> map02_ref
;
50 for (size_t i
= 0; i
< N2
; ++i
)
51 map02_ref
.insert(my_pair(title02
[i
], i
));
52 map
<char, int> map03_ref
;
53 for (size_t i
= 0; i
< N3
; ++i
)
54 map03_ref
.insert(my_pair(title03
[i
], i
));
55 map
<char, int> map04_ref
;
56 for (size_t i
= 0; i
< N4
; ++i
)
57 map04_ref
.insert(my_pair(title04
[i
], i
));
59 my_map::size_type size01
, size02
;
63 my_map
map01(less
<char>(), alloc01
);
64 size01
= map01
.size();
65 my_map
map02(less
<char>(), alloc01
);
66 size02
= map02
.size();
69 VERIFY( map01
.size() == size02
);
70 VERIFY( map01
.empty() );
71 VERIFY( map02
.size() == size01
);
72 VERIFY( map02
.empty() );
74 my_map
map03(less
<char>(), alloc01
);
75 size01
= map03
.size();
76 my_map
map04(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
77 size02
= map04
.size();
80 VERIFY( map03
.size() == size02
);
81 VERIFY( equal(map03
.begin(), map03
.end(), map02_ref
.begin()) );
82 VERIFY( map04
.size() == size01
);
83 VERIFY( map04
.empty() );
85 my_map
map05(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
86 size01
= map05
.size();
87 my_map
map06(map02_ref
.begin(), map02_ref
.end(), less
<char>(), alloc01
);
88 size02
= map06
.size();
91 VERIFY( map05
.size() == size02
);
92 VERIFY( equal(map05
.begin(), map05
.end(), map02_ref
.begin()) );
93 VERIFY( map06
.size() == size01
);
94 VERIFY( equal(map06
.begin(), map06
.end(), map01_ref
.begin()) );
96 my_map
map07(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
97 size01
= map07
.size();
98 my_map
map08(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
99 size02
= map08
.size();
102 VERIFY( map07
.size() == size02
);
103 VERIFY( equal(map07
.begin(), map07
.end(), map03_ref
.begin()) );
104 VERIFY( map08
.size() == size01
);
105 VERIFY( equal(map08
.begin(), map08
.end(), map01_ref
.begin()) );
107 my_map
map09(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
108 size01
= map09
.size();
109 my_map
map10(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc01
);
110 size02
= map10
.size();
113 VERIFY( map09
.size() == size02
);
114 VERIFY( equal(map09
.begin(), map09
.end(), map04_ref
.begin()) );
115 VERIFY( map10
.size() == size01
);
116 VERIFY( equal(map10
.begin(), map10
.end(), map03_ref
.begin()) );
118 my_map
map11(map04_ref
.begin(), map04_ref
.end(), less
<char>(), alloc01
);
119 size01
= map11
.size();
120 my_map
map12(map01_ref
.begin(), map01_ref
.end(), less
<char>(), alloc01
);
121 size02
= map12
.size();
124 VERIFY( map11
.size() == size02
);
125 VERIFY( equal(map11
.begin(), map11
.end(), map01_ref
.begin()) );
126 VERIFY( map12
.size() == size01
);
127 VERIFY( equal(map12
.begin(), map12
.end(), map04_ref
.begin()) );
129 my_map
map13(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
130 size01
= map13
.size();
131 my_map
map14(map03_ref
.begin(), map03_ref
.end(), less
<char>(), alloc01
);
132 size02
= map14
.size();
135 VERIFY( map13
.size() == size02
);
136 VERIFY( equal(map13
.begin(), map13
.end(), map03_ref
.begin()) );
137 VERIFY( map14
.size() == size01
);
138 VERIFY( equal(map14
.begin(), map14
.end(), map03_ref
.begin()) );