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