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// <list>
10
11// void merge(list& x);
12// If (addressof(x) == this) does nothing; otherwise ...
13
14#include <list>
15#include <cassert>
16
17#include "test_macros.h"
18#include "min_allocator.h"
19
20int main(int, char**) {
21 {
22 int a1[] = {1, 3, 7, 9, 10};
23 int a2[] = {0, 2, 4, 5, 6, 8, 11};
24 int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
25 std::list<int> c1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
26 std::list<int> c2(a2, a2 + sizeof(a2) / sizeof(a2[0]));
27 c1.merge(x&: c2);
28 assert(c1 == std::list<int>(a3, a3 + sizeof(a3) / sizeof(a3[0])));
29 assert(c2.empty());
30 }
31
32 {
33 int a1[] = {1, 3, 7, 9, 10};
34 std::list<int> c1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
35 c1.merge(x&: c1);
36 assert((c1 == std::list<int>(a1, a1 + sizeof(a1) / sizeof(a1[0]))));
37 }
38
39#if TEST_STD_VER >= 11
40 {
41 int a1[] = {1, 3, 7, 9, 10};
42 int a2[] = {0, 2, 4, 5, 6, 8, 11};
43 int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
44 std::list<int, min_allocator<int>> c1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
45 std::list<int, min_allocator<int>> c2(a2, a2 + sizeof(a2) / sizeof(a2[0]));
46 c1.merge(c2);
47 assert((c1 == std::list<int, min_allocator<int>>(a3, a3 + sizeof(a3) / sizeof(a3[0]))));
48 assert(c2.empty());
49 }
50#endif
51
52 return 0;
53}
54

source code of libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp