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