]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/operations/1.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / operations / 1.cc
CommitLineData
748086b7 1// Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
17472bb6
BK
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
748086b7 6// Free Software Foundation; either version 3, or (at your option)
17472bb6
BK
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without Pred the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17472bb6
BK
17
18// 23.2.2.4 list operations [lib.list.ops]
19
20#include <list>
21#include <testsuite_hooks.h>
22
11f10e6b 23bool test __attribute__((unused)) = true;
17472bb6
BK
24
25// splice(p, x) + remove + reverse
26void
27test01()
28{
29 const int K = 417;
30 const int A[] = {1, 2, 3, 4, 5};
31 const int B[] = {K, K, K, K, K};
11f10e6b
BK
32 const std::size_t N = sizeof(A) / sizeof(int);
33 const std::size_t M = sizeof(B) / sizeof(int);
17472bb6
BK
34
35 std::list<int> list0101(A, A + N);
36 std::list<int> list0102(B, B + M);
37 std::list<int>::iterator p = list0101.begin();
38
39 VERIFY(list0101.size() == N);
40 VERIFY(list0102.size() == M);
41
42 ++p;
43 list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
44 VERIFY(list0101.size() == N + M);
45 VERIFY(list0102.size() == 0);
46
47 // remove range from middle
48 list0101.remove(K);
49 VERIFY(list0101.size() == N);
50
51 // remove first element
52 list0101.remove(1);
53 VERIFY(list0101.size() == N - 1);
54
55 // remove last element
56 list0101.remove(5);
57 VERIFY(list0101.size() == N - 2);
58
59 // reverse
60 list0101.reverse();
61 p = list0101.begin();
62 VERIFY(*p == 4); ++p;
63 VERIFY(*p == 3); ++p;
64 VERIFY(*p == 2); ++p;
65 VERIFY(p == list0101.end());
66}
67
11f10e6b 68int main(void)
17472bb6
BK
69{
70 test01();
71 return 0;
72}
f90e600a 73