| 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 | // UNSUPPORTED: c++03 |
| 10 | |
| 11 | // <forward_list> |
| 12 | |
| 13 | // forward_list(initializer_list<value_type> il, const allocator_type& a); // constexpr since C++26 |
| 14 | |
| 15 | #include <forward_list> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "test_allocator.h" |
| 20 | #include "min_allocator.h" |
| 21 | |
| 22 | TEST_CONSTEXPR_CXX26 bool test() { |
| 23 | { |
| 24 | typedef int T; |
| 25 | typedef test_allocator<T> A; |
| 26 | typedef std::forward_list<T, A> C; |
| 27 | C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A(14)); |
| 28 | int n = 0; |
| 29 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 30 | assert(*i == n); |
| 31 | assert(n == 10); |
| 32 | assert(c.get_allocator() == A(14)); |
| 33 | } |
| 34 | { |
| 35 | typedef int T; |
| 36 | typedef min_allocator<T> A; |
| 37 | typedef std::forward_list<T, A> C; |
| 38 | C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A()); |
| 39 | int n = 0; |
| 40 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 41 | assert(*i == n); |
| 42 | assert(n == 10); |
| 43 | assert(c.get_allocator() == A()); |
| 44 | } |
| 45 | |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | int main(int, char**) { |
| 50 | assert(test()); |
| 51 | #if TEST_STD_VER >= 26 |
| 52 | static_assert(test()); |
| 53 | #endif |
| 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |