]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / list / list.modifiers / insert_iter_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, const value_type& x);
13
14 #include <list>
15 #include <cstdlib>
16 #include <cassert>
17
18 #include "test_macros.h"
19 #include "min_allocator.h"
20 #include "count_new.hpp"
21
22 template <class List>
23 void test()
24 {
25     int a1[] = {1, 2, 3};
26     int a2[] = {1, 4, 2, 3};
27     List l1(a1, a1+3);
28     typename List::iterator i = l1.insert(next(l1.cbegin()), 4);
29     assert(i == next(l1.begin()));
30     assert(l1.size() == 4);
31     assert(distance(l1.begin(), l1.end()) == 4);
32     assert(l1 == List(a2, a2+4));
33
34 #if !defined(TEST_HAS_NO_EXCEPTIONS) && !defined(DISABLE_NEW_COUNT)
35     globalMemCounter.throw_after = 0;
36     int save_count = globalMemCounter.outstanding_new;
37     try
38     {
39         i = l1.insert(i, 5);
40         assert(false);
41     }
42     catch (...)
43     {
44     }
45     assert(globalMemCounter.checkOutstandingNewEq(save_count));
46     assert(l1 == List(a2, a2+4));
47 #endif
48 }
49
50 int main()
51 {
52     test<std::list<int> >();
53 #if TEST_STD_VER >= 11
54     test<std::list<int, min_allocator<int>>>();
55 #endif
56 }