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 <InputIterator Iter>
12// iterator insert(const_iterator position, Iter first, Iter last);
13
14#include <list>
15#include <cstdlib>
16#include <cassert>
17
18#include "test_macros.h"
19#include "test_iterators.h"
20#include "min_allocator.h"
21#include "count_new.h"
22
23template <class List>
24void test() {
25 int a1[] = {1, 2, 3};
26 List l1;
27 typename List::iterator i = l1.insert(l1.begin(), a1, a1+3);
28 assert(i == l1.begin());
29 assert(l1.size() == 3);
30 assert(std::distance(l1.begin(), l1.end()) == 3);
31 i = l1.begin();
32 assert(*i == 1);
33 ++i;
34 assert(*i == 2);
35 ++i;
36 assert(*i == 3);
37 int a2[] = {4, 5, 6};
38 i = l1.insert(i, a2, a2+3);
39 assert(*i == 4);
40 assert(l1.size() == 6);
41 assert(std::distance(l1.begin(), l1.end()) == 6);
42 i = l1.begin();
43 assert(*i == 1);
44 ++i;
45 assert(*i == 2);
46 ++i;
47 assert(*i == 4);
48 ++i;
49 assert(*i == 5);
50 ++i;
51 assert(*i == 6);
52 ++i;
53 assert(*i == 3);
54
55#if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)
56 globalMemCounter.throw_after = 2;
57 int save_count = globalMemCounter.outstanding_new;
58 try
59 {
60 i = l1.insert(i, a2, a2+3);
61 assert(false);
62 }
63 catch (...)
64 {
65 }
66 assert(globalMemCounter.checkOutstandingNewEq(save_count));
67 assert(l1.size() == 6);
68 assert(std::distance(l1.begin(), l1.end()) == 6);
69 i = l1.begin();
70 assert(*i == 1);
71 ++i;
72 assert(*i == 2);
73 ++i;
74 assert(*i == 4);
75 ++i;
76 assert(*i == 5);
77 ++i;
78 assert(*i == 6);
79 ++i;
80 assert(*i == 3);
81#endif
82}
83
84int main(int, char**)
85{
86 test<std::list<int> >();
87#if TEST_STD_VER >= 11
88 test<std::list<int, min_allocator<int>>>();
89#endif
90
91 return 0;
92}
93

source code of libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp