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); // 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;
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(10));
35 }
36#if TEST_STD_VER >= 11
37 {
38 typedef int T;
39 typedef other_allocator<int> A;
40 typedef std::forward_list<T, A> C;
41 const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
42 C c0(std::begin(t), std::end(t), A(10));
43 C c = c0;
44 int n = 0;
45 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
46 assert(*i == n);
47 assert(n == std::end(t) - std::begin(t));
48 assert(c == c0);
49 assert(c.get_allocator() == A(-2));
50 }
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;
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.pass.cpp