OSDN Git Service

2009-06-17 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / operations / 1.h
1 // Copyright (C) 2001, 2004, 2005, 2009 Free Software Foundation, Inc.
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
6 // Free Software Foundation; either version 3, or (at your option)
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
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // 23.2.2.4 list operations [lib.list.ops]
19
20 #include <testsuite_hooks.h>
21
22 // splice(p, x) + remove + reverse
23 template<typename _Tp>
24 void
25 operations01()
26 {
27   bool test __attribute__((unused)) = true;
28   typedef _Tp list_type;
29   typedef typename list_type::iterator iterator;
30
31   const int K = 417;
32   const int A[] = {1, 2, 3, 4, 5};
33   const int B[] = {K, K, K, K, K};
34   const std::size_t N = sizeof(A) / sizeof(int);
35   const std::size_t M = sizeof(B) / sizeof(int);
36
37   list_type list0101(A, A + N);
38   list_type list0102(B, B + M);
39   iterator p = list0101.begin();
40
41   VERIFY(list0101.size() == N);
42   VERIFY(list0102.size() == M);
43
44   ++p;
45   list0101.splice(p, list0102); // [1 K K K K K 2 3 4 5]
46   VERIFY(list0101.size() == N + M);
47   VERIFY(list0102.size() == 0);
48
49   // remove range from middle
50   list0101.remove(K);
51   VERIFY(list0101.size() == N);
52
53   // remove first element
54   list0101.remove(1);
55   VERIFY(list0101.size() == N - 1);
56
57   // remove last element
58   list0101.remove(5);
59   VERIFY(list0101.size() == N - 2);
60
61   // reverse
62   list0101.reverse();
63   p = list0101.begin();
64   VERIFY(*p == 4); ++p;
65   VERIFY(*p == 3); ++p;
66   VERIFY(*p == 2); ++p;
67   VERIFY(p == list0101.end());
68 }