| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <forward_list> |
| 10 | |
| 11 | // void reverse(); // constexpr since C++26 |
| 12 | |
| 13 | #include <forward_list> |
| 14 | #include <iterator> |
| 15 | #include <algorithm> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | template <class C> |
| 22 | TEST_CONSTEXPR_CXX26 void test1(int N) { |
| 23 | C c; |
| 24 | for (int i = 0; i < N; ++i) |
| 25 | c.push_front(i); |
| 26 | c.reverse(); |
| 27 | assert(std::distance(c.begin(), c.end()) == N); |
| 28 | typename C::const_iterator j = c.begin(); |
| 29 | for (int i = 0; i < N; ++i, ++j) |
| 30 | assert(*j == i); |
| 31 | } |
| 32 | |
| 33 | TEST_CONSTEXPR_CXX26 bool test() { |
| 34 | for (int i = 0; i < 10; ++i) |
| 35 | test1<std::forward_list<int> >(i); |
| 36 | #if TEST_STD_VER >= 11 |
| 37 | for (int i = 0; i < 10; ++i) |
| 38 | test1<std::forward_list<int, min_allocator<int>> >(i); |
| 39 | #endif |
| 40 | |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | int main(int, char**) { |
| 45 | assert(test()); |
| 46 | #if TEST_STD_VER >= 26 |
| 47 | static_assert(test()); |
| 48 | #endif |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |