1 // 2005-12-20 Paolo Carlini <pcarlini@suse.de>
3 // Copyright (C) 2005-2025 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 // 23.2.1.3 deque::swap
23 #include <testsuite_hooks.h>
24 #include <testsuite_allocator.h>
26 // uneq_allocator as a non-empty allocator.
32 typedef __gnu_test::uneq_allocator
<char> my_alloc
;
33 typedef deque
<char, my_alloc
> my_deque
;
35 const char title01
[] = "Rivers of sand";
36 const char title02
[] = "Concret PH";
37 const char title03
[] = "Sonatas and Interludes for Prepared Piano";
38 const char title04
[] = "never as tired as when i'm waking up";
40 const size_t N1
= sizeof(title01
);
41 const size_t N2
= sizeof(title02
);
42 const size_t N3
= sizeof(title03
);
43 const size_t N4
= sizeof(title04
);
45 my_deque::size_type size01
, size02
;
49 my_deque
deq01(alloc01
);
50 size01
= deq01
.size();
51 my_deque
deq02(alloc01
);
52 size02
= deq02
.size();
55 VERIFY( deq01
.size() == size02
);
56 VERIFY( deq01
.empty() );
57 VERIFY( deq02
.size() == size01
);
58 VERIFY( deq02
.empty() );
60 my_deque
deq03(alloc01
);
61 size01
= deq03
.size();
62 my_deque
deq04(title02
, title02
+ N2
, alloc01
);
63 size02
= deq04
.size();
66 VERIFY( deq03
.size() == size02
);
67 VERIFY( equal(deq03
.begin(), deq03
.end(), title02
) );
68 VERIFY( deq04
.size() == size01
);
69 VERIFY( deq04
.empty() );
71 my_deque
deq05(title01
, title01
+ N1
, alloc01
);
72 size01
= deq05
.size();
73 my_deque
deq06(title02
, title02
+ N2
, alloc01
);
74 size02
= deq06
.size();
77 VERIFY( deq05
.size() == size02
);
78 VERIFY( equal(deq05
.begin(), deq05
.end(), title02
) );
79 VERIFY( deq06
.size() == size01
);
80 VERIFY( equal(deq06
.begin(), deq06
.end(), title01
) );
82 my_deque
deq07(title01
, title01
+ N1
, alloc01
);
83 size01
= deq07
.size();
84 my_deque
deq08(title03
, title03
+ N3
, alloc01
);
85 size02
= deq08
.size();
88 VERIFY( deq07
.size() == size02
);
89 VERIFY( equal(deq07
.begin(), deq07
.end(), title03
) );
90 VERIFY( deq08
.size() == size01
);
91 VERIFY( equal(deq08
.begin(), deq08
.end(), title01
) );
93 my_deque
deq09(title03
, title03
+ N3
, alloc01
);
94 size01
= deq09
.size();
95 my_deque
deq10(title04
, title04
+ N4
, alloc01
);
96 size02
= deq10
.size();
99 VERIFY( deq09
.size() == size02
);
100 VERIFY( equal(deq09
.begin(), deq09
.end(), title04
) );
101 VERIFY( deq10
.size() == size01
);
102 VERIFY( equal(deq10
.begin(), deq10
.end(), title03
) );
104 my_deque
deq11(title04
, title04
+ N4
, alloc01
);
105 size01
= deq11
.size();
106 my_deque
deq12(title01
, title01
+ N1
, alloc01
);
107 size02
= deq12
.size();
110 VERIFY( deq11
.size() == size02
);
111 VERIFY( equal(deq11
.begin(), deq11
.end(), title01
) );
112 VERIFY( deq12
.size() == size01
);
113 VERIFY( equal(deq12
.begin(), deq12
.end(), title04
) );
115 my_deque
deq13(title03
, title03
+ N3
, alloc01
);
116 size01
= deq13
.size();
117 my_deque
deq14(title03
, title03
+ N3
, alloc01
);
118 size02
= deq14
.size();
121 VERIFY( deq13
.size() == size02
);
122 VERIFY( equal(deq13
.begin(), deq13
.end(), title03
) );
123 VERIFY( deq14
.size() == size01
);
124 VERIFY( equal(deq14
.begin(), deq14
.end(), title03
) );