| 1 | // Copyright (C) 2017-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 <deque> |
| 21 | #include <testsuite_iterators.h> |
| 22 | #include <testsuite_allocator.h> |
| 23 | |
| 24 | template<typename T> |
| 25 | using input_iterator_seq |
| 26 | = __gnu_test::test_container<T, __gnu_test::input_iterator_wrapper>; |
| 27 | |
| 28 | template<typename T, typename U> struct require_same; |
| 29 | template<typename T> struct require_same<T, T> { using type = void; }; |
| 30 | |
| 31 | template<typename T, typename U> |
| 32 | typename require_same<T, U>::type |
| 33 | check_type(U&) { } |
| 34 | |
| 35 | void |
| 36 | test01() |
| 37 | { |
| 38 | std::deque<unsigned> s0; |
| 39 | |
| 40 | std::deque s1 = s0; |
| 41 | check_type<std::deque<unsigned>>(s1); |
| 42 | |
| 43 | std::deque s2 = std::move(s0); |
| 44 | check_type<std::deque<unsigned>>(s2); |
| 45 | |
| 46 | const std::deque s3 = s0; |
| 47 | check_type<const std::deque<unsigned>>(s3); |
| 48 | |
| 49 | const std::deque s4 = s3; |
| 50 | check_type<const std::deque<unsigned>>(s4); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | test02() |
| 55 | { |
| 56 | unsigned a[1] = {}; |
| 57 | input_iterator_seq<unsigned> seq(a); |
| 58 | |
| 59 | std::deque s1(seq.begin(), seq.end()); |
| 60 | check_type<std::deque<unsigned>>(s1); |
| 61 | |
| 62 | std::deque s2(seq.begin(), seq.end(), std::allocator<unsigned>()); |
| 63 | check_type<std::deque<unsigned>>(s2); |
| 64 | |
| 65 | std::deque s3(1U, 2L); |
| 66 | check_type<std::deque<long>>(s3); |
| 67 | |
| 68 | std::deque s4(1U, 2L, std::allocator<long>()); |
| 69 | check_type<std::deque<long>>(s4); |
| 70 | } |
| 71 | |
| 72 | struct Pool; |
| 73 | |
| 74 | template<typename T> |
| 75 | struct Alloc : __gnu_test::SimpleAllocator<T> |
| 76 | { |
| 77 | Alloc(Pool*) { } |
| 78 | |
| 79 | template<typename U> |
| 80 | Alloc(const Alloc<U>&) { } |
| 81 | }; |
| 82 | |
| 83 | void |
| 84 | test_p1518r2() |
| 85 | { |
| 86 | // P1518R2 - Stop overconstraining allocators in container deduction guides. |
| 87 | // This is a C++23 feature but we support it for C++17 too. |
| 88 | |
| 89 | using Deque = std::deque<unsigned, Alloc<unsigned>>; |
| 90 | Pool* p = nullptr; |
| 91 | Deque d(p); |
| 92 | |
| 93 | std::deque s1(d, p); |
| 94 | check_type<Deque>(s1); |
| 95 | |
| 96 | std::deque s2(std::move(d), p); |
| 97 | check_type<Deque>(s2); |
| 98 | } |