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// template <class Compare> void merge(list& x, Compare comp);
12// If (addressof(x) == this) does nothing; otherwise ...
13
14#include <list>
15#include <functional>
16#include <cassert>
17
18#include "test_macros.h"
19#include "min_allocator.h"
20
21int main(int, char**) {
22 {
23 int a1[] = {10, 9, 7, 3, 1};
24 int a2[] = {11, 8, 6, 5, 4, 2, 0};
25 int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
26 std::list<int> c1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
27 std::list<int> c2(a2, a2 + sizeof(a2) / sizeof(a2[0]));
28 c1.merge(x&: c2, comp: std::greater<int>());
29 assert(c1 == std::list<int>(a3, a3 + sizeof(a3) / sizeof(a3[0])));
30 assert(c2.empty());
31 }
32 {
33 int a1[] = {10, 9, 7, 3, 1};
34 std::list<int> c1(a1, a1 + sizeof(a1) / sizeof(a1[0]));
35 c1.merge(x&: c1, comp: std::greater<int>());
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[] = {10, 9, 7, 3, 1};
42 int a2[] = {11, 8, 6, 5, 4, 2, 0};
43 int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
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, std::greater<int>());
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_comp.pass.cpp