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); |
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 | |
21 | int main(int, char**) |
22 | { |
23 | { |
24 | typedef int T; |
25 | typedef test_allocator<int> A; |
26 | typedef std::forward_list<T, A> C; |
27 | const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
28 | C c0(std::begin(t), std::end(t), A(10)); |
29 | C c(c0, A(9)); |
30 | int n = 0; |
31 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
32 | assert(*i == n); |
33 | assert(n == std::end(t) - std::begin(t)); |
34 | assert(c == c0); |
35 | assert(c.get_allocator() == A(9)); |
36 | } |
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(arr: t), std::end(arr: t), A(10)); |
43 | C c(c0, A(9)); |
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(9)); |
50 | } |
51 | #if TEST_STD_VER >= 11 |
52 | { |
53 | typedef int T; |
54 | typedef min_allocator<int> A; |
55 | typedef std::forward_list<T, A> C; |
56 | const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
57 | C c0(std::begin(t), std::end(t), A()); |
58 | C c(c0, A()); |
59 | int n = 0; |
60 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
61 | assert(*i == n); |
62 | assert(n == std::end(t) - std::begin(t)); |
63 | assert(c == c0); |
64 | assert(c.get_allocator() == A()); |
65 | } |
66 | #endif |
67 | |
68 | return 0; |
69 | } |
70 | |