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 | // void assign(InputIterator first, InputIterator last); |
13 | |
14 | #include <forward_list> |
15 | #include <cassert> |
16 | #include <iterator> |
17 | |
18 | #include "test_macros.h" |
19 | #include "test_iterators.h" |
20 | #include "min_allocator.h" |
21 | |
22 | int main(int, char**) |
23 | { |
24 | { |
25 | typedef int T; |
26 | typedef std::forward_list<T> C; |
27 | const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
28 | const T t1[] = {10, 11, 12, 13}; |
29 | C c(std::begin(arr: t1), std::end(arr: t1)); |
30 | typedef cpp17_input_iterator<const T*> I; |
31 | c.assign(n: I(std::begin(arr: t0)), val: I(std::end(arr: t0))); |
32 | int n = 0; |
33 | for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) |
34 | assert(*i == n); |
35 | assert(n == 10); |
36 | } |
37 | { |
38 | typedef int T; |
39 | typedef std::forward_list<T> C; |
40 | const T t0[] = {10, 11, 12, 13}; |
41 | const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
42 | C c(std::begin(arr: t1), std::end(arr: t1)); |
43 | typedef cpp17_input_iterator<const T*> I; |
44 | c.assign(n: I(std::begin(arr: t0)), val: I(std::end(arr: t0))); |
45 | int n = 0; |
46 | for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) |
47 | assert(*i == 10+n); |
48 | assert(n == 4); |
49 | } |
50 | #if TEST_STD_VER >= 11 |
51 | { |
52 | typedef int T; |
53 | typedef std::forward_list<T, min_allocator<T>> C; |
54 | const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
55 | const T t1[] = {10, 11, 12, 13}; |
56 | C c(std::begin(t1), std::end(t1)); |
57 | typedef cpp17_input_iterator<const T*> I; |
58 | c.assign(I(std::begin(t0)), I(std::end(t0))); |
59 | int n = 0; |
60 | for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) |
61 | assert(*i == n); |
62 | assert(n == 10); |
63 | } |
64 | { |
65 | typedef int T; |
66 | typedef std::forward_list<T, min_allocator<T>> C; |
67 | const T t0[] = {10, 11, 12, 13}; |
68 | const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
69 | C c(std::begin(t1), std::end(t1)); |
70 | typedef cpp17_input_iterator<const T*> I; |
71 | c.assign(I(std::begin(t0)), I(std::end(t0))); |
72 | int n = 0; |
73 | for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, (void) ++n) |
74 | assert(*i == 10+n); |
75 | assert(n == 4); |
76 | } |
77 | #endif |
78 | |
79 | return 0; |
80 | } |
81 | |