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

source code of libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp