| 1 | // { dg-do run { target c++23 } } |
| 2 | |
| 3 | #include <list> |
| 4 | #include <queue> |
| 5 | #include <span> |
| 6 | #include <testsuite_hooks.h> |
| 7 | #include <testsuite_iterators.h> |
| 8 | |
| 9 | template<typename Range, typename Cont> |
| 10 | constexpr void |
| 11 | do_test() |
| 12 | { |
| 13 | // The queue's value_type. |
| 14 | using V = typename Cont::value_type; |
| 15 | |
| 16 | // The range's value_type. |
| 17 | using T = std::ranges::range_value_t<Range>; |
| 18 | T a[]{1,2,3,4,5,6,7,8,9}; |
| 19 | |
| 20 | auto eq = [](std::queue<V, Cont> l, std::span<T> r) { |
| 21 | if (l.size() != r.size()) |
| 22 | return false; |
| 23 | for (auto const& v : r) { |
| 24 | if (v != l.front()) |
| 25 | return false; |
| 26 | l.pop(); |
| 27 | } |
| 28 | return true; |
| 29 | }; |
| 30 | |
| 31 | std::queue<V, Cont> q; |
| 32 | q.push_range(Range(a, a+0)); |
| 33 | VERIFY( q.empty() ); |
| 34 | |
| 35 | q.push_range(Range(a, a+4)); |
| 36 | VERIFY( eq(q, {a, 4}) ); |
| 37 | |
| 38 | q.push_range(Range(a+4, a+9)); |
| 39 | VERIFY( eq(q, {a, 9}) ); |
| 40 | } |
| 41 | |
| 42 | template<typename T, typename Alloc = std::allocator<T>> |
| 43 | struct NoAppendRangeCont : std::deque<T, Alloc> |
| 44 | { |
| 45 | template<typename R> |
| 46 | void append_range(R&&) = delete; |
| 47 | }; |
| 48 | |
| 49 | template<typename Range> |
| 50 | void |
| 51 | do_test_c() |
| 52 | { |
| 53 | do_test<Range, std::deque<int>>(); |
| 54 | do_test<Range, std::list<int>>(); |
| 55 | do_test<Range, NoAppendRangeCont<int>>(); |
| 56 | } |
| 57 | |
| 58 | bool |
| 59 | test_ranges() |
| 60 | { |
| 61 | using namespace __gnu_test; |
| 62 | |
| 63 | do_test_c<test_forward_range<int>>(); |
| 64 | do_test_c<test_range_nocopy<int, input_iterator_wrapper_nocopy>>(); |
| 65 | do_test_c<test_forward_range<short>>(); |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | |
| 70 | int main() |
| 71 | { |
| 72 | test_ranges(); |
| 73 | } |