| 1 | // Copyright (C) 2001-2025 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 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 COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // 23.2.2.1 list constructors, copy, and assignment |
| 19 | |
| 20 | #include <testsuite_hooks.h> |
| 21 | |
| 22 | // A nontrivial type. |
| 23 | template<typename T> |
| 24 | struct A { }; |
| 25 | |
| 26 | // Another nontrivial type |
| 27 | struct B { }; |
| 28 | |
| 29 | // Fill constructor |
| 30 | // |
| 31 | // This test verifies the following. |
| 32 | // 23.2.2.1 explicit list(size_type n, const T& v = T(), const a& = Allocator()) |
| 33 | // 23.2.2 const_iterator begin() const |
| 34 | // 23.2.2 const_iterator end() const |
| 35 | // 23.2.2 size_type size() const |
| 36 | // |
| 37 | template<typename _Tp> |
| 38 | void |
| 39 | cons021() |
| 40 | { |
| 41 | const std::size_t LIST_SIZE = 5; |
| 42 | const int INIT_VALUE = 7; |
| 43 | std::size_t count; |
| 44 | |
| 45 | typedef _Tp list_type; |
| 46 | typedef typename list_type::const_iterator const_iterator; |
| 47 | const_iterator i; |
| 48 | |
| 49 | // default value |
| 50 | list_type list0202(LIST_SIZE); |
| 51 | for (i = list0202.begin(), count = 0; |
| 52 | i != list0202.end(); |
| 53 | ++i, ++count) |
| 54 | VERIFY(*i == 0); |
| 55 | VERIFY(count == LIST_SIZE); |
| 56 | VERIFY(list0202.size() == LIST_SIZE); |
| 57 | |
| 58 | // explicit value |
| 59 | list_type list0203(LIST_SIZE, INIT_VALUE); |
| 60 | for (i = list0203.begin(), count = 0; |
| 61 | i != list0203.end(); |
| 62 | ++i, ++count) |
| 63 | VERIFY(*i == INIT_VALUE); |
| 64 | VERIFY(count == LIST_SIZE); |
| 65 | VERIFY(list0203.size() == LIST_SIZE); |
| 66 | } |
| 67 | |
| 68 | template<typename _Tp> |
| 69 | void |
| 70 | cons022() |
| 71 | { |
| 72 | // nontrivial value_type |
| 73 | typedef _Tp list_type; |
| 74 | const std::size_t LIST_SIZE = 5; |
| 75 | list_type list0201(LIST_SIZE); |
| 76 | } |