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// <list>
12
13// list(list&& c, const allocator_type& a);
14
15#include <list>
16#include <cassert>
17#include "test_macros.h"
18#include "MoveOnly.h"
19#include "test_allocator.h"
20#include "min_allocator.h"
21
22int main(int, char**) {
23 {
24 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
25 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
26 for (int i = 1; i <= 3; ++i) {
27 l.push_back(i);
28 lo.push_back(i);
29 }
30 std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(6));
31 assert(l2 == lo);
32 assert(!l.empty());
33 assert(l2.get_allocator() == test_allocator<MoveOnly>(6));
34 }
35 {
36 std::list<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
37 std::list<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
38 for (int i = 1; i <= 3; ++i) {
39 l.push_back(i);
40 lo.push_back(i);
41 }
42 std::list<MoveOnly, test_allocator<MoveOnly> > l2(std::move(l), test_allocator<MoveOnly>(5));
43 assert(l2 == lo);
44 assert(l.empty());
45 assert(l2.get_allocator() == test_allocator<MoveOnly>(5));
46 }
47 {
48 std::list<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
49 std::list<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
50 for (int i = 1; i <= 3; ++i) {
51 l.push_back(i);
52 lo.push_back(i);
53 }
54 std::list<MoveOnly, other_allocator<MoveOnly> > l2(std::move(l), other_allocator<MoveOnly>(4));
55 assert(l2 == lo);
56 assert(!l.empty());
57 assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
58 }
59 {
60 std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
61 std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
62 for (int i = 1; i <= 3; ++i) {
63 l.push_back(i);
64 lo.push_back(i);
65 }
66 std::list<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>());
67 assert(l2 == lo);
68 assert(l.empty());
69 assert(l2.get_allocator() == min_allocator<MoveOnly>());
70 }
71
72 return 0;
73}
74

source code of libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp