]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / list / list.modifiers / insert_iter_size_value.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <list>
11
12 // iterator insert(const_iterator position, size_type n, const value_type& x);
13
14 // UNSUPPORTED: sanitizer-new-delete
15
16 #include <list>
17 #include <cstdlib>
18 #include <cassert>
19
20 #include "min_allocator.h"
21 #include "count_new.hpp"
22 #include "test_macros.h"
23
24 template <class List>
25 void test() {
26     int a1[] = {1, 2, 3};
27     int a2[] = {1, 4, 4, 4, 4, 4, 2, 3};
28     List l1(a1, a1+3);
29     typename List::iterator i = l1.insert(next(l1.cbegin()), 5, 4);
30     assert(i == next(l1.begin()));
31     assert(l1 == List(a2, a2+8));
32 #ifndef TEST_HAS_NO_EXCEPTIONS
33     globalMemCounter.throw_after = 4;
34     int save_count = globalMemCounter.outstanding_new;
35     try
36     {
37         i = l1.insert(i, 5, 5);
38         assert(false);
39     }
40     catch (...)
41     {
42     }
43     assert(globalMemCounter.checkOutstandingNewEq(save_count));
44     assert(l1 == List(a2, a2+8));
45 #endif
46 }
47
48 int main()
49 {
50     test<std::list<int> >();
51 #if TEST_STD_VER >= 11
52     test<std::list<int, min_allocator<int>>>();
53 #endif
54 }