]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/list/cons/2.cc
re PR testsuite/39696 (gcc.dg/tree-ssa/ssa-ccp-25.c scan-tree-dump doesn't work on...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / list / cons / 2.cc
CommitLineData
b0ea9c01 1// Copyright (C) 2001, 2004, 2005 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
6// Free Software Foundation; either version 2, 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 even 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 COPYING. If not, write to the Free
83f51799 16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17472bb6
BK
17// USA.
18
19// 23.2.2.1 list constructors, copy, and assignment
20
21#include <list>
22#include <testsuite_hooks.h>
23
11f10e6b 24bool test __attribute__((unused)) = true;
17472bb6
BK
25
26// A nontrivial type.
27template<typename T>
28 struct A { };
29
30// Another nontrivial type
31struct B { };
32
33// A nontrivial type convertible from an int
34struct C {
35 C(int i) : i_(i) { }
36 bool operator==(const C& rhs) { return i_ == rhs.i_; }
37 int i_;
38};
39
40// Fill constructor
41//
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
47//
48void
49test02()
50{
11f10e6b 51 const std::size_t LIST_SIZE = 5;
17472bb6 52 const int INIT_VALUE = 7;
11f10e6b 53 std::size_t count;
17472bb6
BK
54 std::list<int>::const_iterator i;
55
56 // nontrivial value_type
57 std::list< A<B> > list0201(LIST_SIZE);
58
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);
67
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);
76}
77
78int main()
79{
80 test02();
81 return 0;
82}