This commit was manufactured by cvs2svn to create branch
[official-gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / cons / 2.cc
blobb837d85a386b32ace51d943fd4e4f13286cf2c9b
1 // Copyright (C) 2001, 2004 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 2, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING. If not, write to the Free
16 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 // USA.
19 // 23.2.2.1 list constructors, copy, and assignment
21 #include <list>
22 #include <testsuite_hooks.h>
24 bool test __attribute__((unused)) = true;
26 // A nontrivial type.
27 template<typename T>
28 struct A { };
30 // Another nontrivial type
31 struct B { };
33 // A nontrivial type convertible from an int
34 struct C {
35 C(int i) : i_(i) { }
36 bool operator==(const C& rhs) { return i_ == rhs.i_; }
37 int i_;
40 // Fill constructor
42 // This test verifies the following.
43 // 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator())
44 // 23.2.2 const_iterator begin() const
45 // 23.2.2 const_iterator end() const
46 // 23.2.2 size_type size() const
48 void
49 test02()
51 const std::size_t LIST_SIZE = 5;
52 const int INIT_VALUE = 7;
53 std::size_t count;
54 std::list<int>::const_iterator i;
56 // nontrivial value_type
57 std::list< A<B> > list0201(LIST_SIZE);
59 // default value
60 std::list<int> list0202(LIST_SIZE);
61 for (i = list0202.begin(), count = 0;
62 i != list0202.end();
63 ++i, ++count)
64 VERIFY(*i == 0);
65 VERIFY(count == LIST_SIZE);
66 VERIFY(list0202.size() == LIST_SIZE);
68 // explicit value
69 std::list<int> list0203(LIST_SIZE, INIT_VALUE);
70 for (i = list0203.begin(), count = 0;
71 i != list0203.end();
72 ++i, ++count)
73 VERIFY(*i == INIT_VALUE);
74 VERIFY(count == LIST_SIZE);
75 VERIFY(list0203.size() == LIST_SIZE);
78 #if !__GXX_WEAK__ && _MT_ALLOCATOR_H
79 // Explicitly instantiate for systems with no COMDAT or weak support.
80 template class __gnu_cxx::__mt_alloc<std::_List_node<A<B> > >;
81 template class __gnu_cxx::__mt_alloc<int>;
82 template class __gnu_cxx::__mt_alloc<std::_List_node<int> >;
83 #endif
85 int main()
87 test02();
88 return 0;