| 1 |
// Copyright (C) 2019-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 |
// { dg-do compile { target c++17 } } |
| 19 |
|
| 20 |
#include <stack> |
| 21 |
#include <deque> |
| 22 |
#include <list> |
| 23 |
#include <testsuite_allocator.h> |
| 24 |
|
| 25 |
template<typename T, typename U> struct require_same; |
| 26 |
template<typename T> struct require_same<T, T> { using type = void; }; |
| 27 |
|
| 28 |
template<typename T, typename U> |
| 29 |
typename require_same<T, U>::type |
| 30 |
check_type(U&) { } |
| 31 |
|
| 32 |
void |
| 33 |
test01() |
| 34 |
{ |
| 35 |
std::stack<unsigned> s0; |
| 36 |
|
| 37 |
std::stack s1 = s0; |
| 38 |
check_type<std::stack<unsigned>>(s1); |
| 39 |
|
| 40 |
std::stack s2 = std::move(s0); |
| 41 |
check_type<std::stack<unsigned>>(s2); |
| 42 |
|
| 43 |
const std::stack s3 = s0; |
| 44 |
check_type<const std::stack<unsigned>>(s3); |
| 45 |
|
| 46 |
const std::stack s4 = s3; |
| 47 |
check_type<const std::stack<unsigned>>(s4); |
| 48 |
|
| 49 |
std::allocator<unsigned> a; |
| 50 |
std::stack s5(s0, a); |
| 51 |
check_type<std::stack<unsigned>>(s5); |
| 52 |
|
| 53 |
std::stack s6(std::move(s0), a); |
| 54 |
check_type<std::stack<unsigned>>(s6); |
| 55 |
|
| 56 |
const std::stack s7(s3, a); |
| 57 |
check_type<const std::stack<unsigned>>(s7); |
| 58 |
} |
| 59 |
|
| 60 |
void |
| 61 |
test02() |
| 62 |
{ |
| 63 |
std::deque<unsigned> d; |
| 64 |
std::list<long> l; |
| 65 |
|
| 66 |
std::stack s1(d); |
| 67 |
check_type<std::stack<unsigned>>(s1); |
| 68 |
|
| 69 |
std::stack s2(d, d.get_allocator()); |
| 70 |
check_type<std::stack<unsigned>>(s2); |
| 71 |
|
| 72 |
std::stack s3(std::move(d)); |
| 73 |
check_type<std::stack<unsigned>>(s3); |
| 74 |
|
| 75 |
std::stack s4(std::move(d), d.get_allocator()); |
| 76 |
check_type<std::stack<unsigned>>(s4); |
| 77 |
|
| 78 |
std::stack s5(l); |
| 79 |
check_type<std::stack<long, std::list<long>>>(s5); |
| 80 |
|
| 81 |
std::stack s6(l, l.get_allocator()); |
| 82 |
check_type<std::stack<long, std::list<long>>>(s6); |
| 83 |
|
| 84 |
std::stack s7(std::move(l)); |
| 85 |
check_type<std::stack<long, std::list<long>>>(s7); |
| 86 |
|
| 87 |
std::stack s8(std::move(l), l.get_allocator()); |
| 88 |
check_type<std::stack<long, std::list<long>>>(s8); |
| 89 |
} |
| 90 |
|
| 91 |
#if __cpp_lib_adaptor_iterator_pair_constructor |
| 92 |
void |
| 93 |
test03() |
| 94 |
{ |
| 95 |
std::list<long> l; |
| 96 |
|
| 97 |
std::stack s1(l.begin(), l.end()); |
| 98 |
check_type<std::stack<long>>(s1); |
| 99 |
|
| 100 |
std::stack s2(l.begin(), l.end(), std::allocator<long>()); |
| 101 |
check_type<std::stack<long>>(s2); |
| 102 |
} |
| 103 |
#endif |