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); // constexpr since C++26
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
24TEST_CONSTEXPR_CXX26 bool test() {
25 {
26 typedef MoveOnly T;
27 typedef test_allocator<T> A;
28 typedef std::forward_list<T, A> C;
29 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
30 typedef std::move_iterator<T*> I;
31 C c0(I(std::begin(t)), I(std::end(t)), A(10));
32 C c = std::move(c0);
33 int n = 0;
34 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, (void)++n)
35 assert(*i == n);
36 assert(n == std::end(t) - std::begin(t));
37 assert(c0.empty());
38 assert(c.get_allocator() == A(10));
39 }
40 {
41 typedef MoveOnly T;
42 typedef other_allocator<T> A;
43 typedef std::forward_list<T, A> C;
44 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
45 typedef std::move_iterator<T*> I;
46 C c0(I(std::begin(arr&: t)), I(std::end(arr&: t)), A(10));
47 C c = std::move(c0);
48 int n = 0;
49 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, (void)++n)
50 assert(*i == n);
51 assert(n == std::end(t) - std::begin(t));
52 assert(c0.empty());
53 assert(c.get_allocator() == A(10));
54 }
55 {
56 typedef MoveOnly T;
57 typedef min_allocator<T> A;
58 typedef std::forward_list<T, A> C;
59 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
60 typedef std::move_iterator<T*> I;
61 C c0(I(std::begin(arr&: t)), I(std::end(arr&: t)), A());
62 C c = std::move(c0);
63 int n = 0;
64 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, (void)++n)
65 assert(*i == n);
66 assert(n == std::end(t) - std::begin(t));
67 assert(c0.empty());
68 assert(c.get_allocator() == A());
69 }
70
71 return true;
72}
73
74int main(int, char**) {
75 assert(test());
76#if TEST_STD_VER >= 26
77 static_assert(test());
78#endif
79
80 return 0;
81}
82

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