OSDN Git Service

a223bc850074cce920590899d11bd62826d84888
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 23_containers / list / check_construct_destroy.cc
1 // 2004-07-26  Matt Austern  <austern@apple.com>
2 //
3 // Copyright (C) 2003, 2009 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.
10 //
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.
15 //
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/>.
19 //
20
21 #include <list>
22 #include <iterator>
23 #include <testsuite_allocator.h>
24
25
26 template<typename _Tp>
27 bool
28 construct_destroy()
29 {
30   typedef _Tp list_type;
31   typedef typename list_type::iterator iterator_type;
32
33   using namespace __gnu_test;
34   const int arr10[10] = { 2, 4, 1, 7, 3, 8, 10, 5, 9, 6 };
35   bool ok = true;
36
37   tracker_allocator_counter::reset();
38   {
39     list_type c;
40     ok = check_construct_destroy("empty container", 0, 0) && ok;
41   }
42   ok = check_construct_destroy("empty container", 0, 0) && ok;
43
44
45   tracker_allocator_counter::reset();
46   {
47     list_type c(arr10, arr10 + 10);
48     ok = check_construct_destroy("Construct from range", 10, 0) && ok;
49   }
50   ok = check_construct_destroy("Construct from range", 10, 10) && ok;
51
52   {
53     list_type c(arr10, arr10 + 10);
54     tracker_allocator_counter::reset();
55     c.insert(c.begin(), arr10[0]);
56     ok = check_construct_destroy("Insert element", 1, 0) && ok;
57   }
58   ok = check_construct_destroy("Insert element", 1, 11) && ok;
59
60   {
61     list_type c(arr10, arr10 + 10);
62     tracker_allocator_counter::reset();
63     iterator_type i5 = c.begin();
64     std::advance(i5, 5);
65     c.insert(i5, arr10, arr10+3);
66     ok = check_construct_destroy("Insert short range", 3, 0) && ok;
67   }
68   ok = check_construct_destroy("Insert short range", 3, 13) && ok;
69
70   {
71     list_type c(arr10, arr10 + 10);
72     tracker_allocator_counter::reset();
73     iterator_type i7 = c.begin();
74     std::advance(i7, 5);
75     c.insert(i7, arr10, arr10+10);
76     ok = check_construct_destroy("Insert long range", 10, 0) && ok;
77   }
78   ok = check_construct_destroy("Insert long range", 10, 20) && ok;
79
80   return ok ? 0 : 1;
81 }
82
83 int main()
84 {
85   construct_destroy<std::list<int, __gnu_test::tracker_allocator<int> > >();
86   return 0;
87 }