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