| 1 | // Copyright (C) 2021-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 run { target c++23 } } |
| 19 | // { dg-add-options no_pch } |
| 20 | |
| 21 | #include <queue> |
| 22 | |
| 23 | #ifndef __cpp_lib_adaptor_iterator_pair_constructor |
| 24 | #error Feature test macro for iterator pair constructors is missing in <queue> |
| 25 | #elif __cpp_lib_adaptor_iterator_pair_constructor != 202106L |
| 26 | #error Feature test macro for iterator pair constructors has wrong value in <queue> |
| 27 | #endif |
| 28 | |
| 29 | #include <testsuite_hooks.h> |
| 30 | #include <testsuite_allocator.h> |
| 31 | |
| 32 | void |
| 33 | test_p1425r4() |
| 34 | { |
| 35 | const int vals[] = { 5, 4, 3, 2, 1, 9 }; |
| 36 | |
| 37 | std::queue<int> q(std::begin(vals), std::end(vals)); |
| 38 | VERIFY( q.size() == std::size(vals) ); |
| 39 | VERIFY( q.front() == 5 ); |
| 40 | VERIFY( q.back() == 9 ); |
| 41 | |
| 42 | using Alloc = __gnu_test::uneq_allocator<int>; |
| 43 | |
| 44 | struct Queue : std::queue<int, std::deque<int, Alloc>> |
| 45 | { |
| 46 | using queue::queue; |
| 47 | |
| 48 | Alloc get_allocator() const { return c.get_allocator(); } |
| 49 | }; |
| 50 | |
| 51 | Alloc a0, a1(1); |
| 52 | Queue q0(std::next(vals), std::end(vals)); |
| 53 | VERIFY( q0.size() == std::size(vals) - 1 ); |
| 54 | VERIFY( q0.front() == 4 ); |
| 55 | VERIFY( q0.back() == 9 ); |
| 56 | VERIFY( q0.get_allocator() == a0 ); |
| 57 | |
| 58 | Queue q1(std::next(vals, 2), std::end(vals), a1); |
| 59 | VERIFY( q1.size() == std::size(vals) - 2 ); |
| 60 | VERIFY( q1.front() == 3 ); |
| 61 | VERIFY( q1.back() == 9 ); |
| 62 | VERIFY( q1.get_allocator() == a1 ); |
| 63 | } |
| 64 | |
| 65 | int main() |
| 66 | { |
| 67 | test_p1425r4(); |
| 68 | } |