1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // iterator erase(const_iterator p)
19 #include "min_allocator.h"
20 #include "test_macros.h"
22 #ifndef TEST_HAS_NO_EXCEPTIONS
25 Throws(int v
) : v_(v
) {}
26 Throws(const Throws
&rhs
) : v_(rhs
.v_
) { if (sThrows
) throw 1; }
27 Throws( Throws
&&rhs
) : v_(rhs
.v_
) { if (sThrows
) throw 1; }
28 Throws
& operator=(const Throws
&rhs
) { v_
= rhs
.v_
; return *this; }
29 Throws
& operator=( Throws
&&rhs
) { v_
= rhs
.v_
; return *this; }
35 bool Throws::sThrows
= false;
40 make(int size
, int start
= 0 )
42 const int b
= 4096 / sizeof(int);
46 init
= (start
+1) / b
+ ((start
+1) % b
!= 0);
51 for (int i
= 0; i
< init
-start
; ++i
)
53 for (int i
= 0; i
< size
; ++i
)
55 for (int i
= 0; i
< start
; ++i
)
64 typedef typename
C::iterator I
;
65 assert(static_cast<std::size_t>(P
) < c1
.size());
66 std::size_t c1_osize
= c1
.size();
67 I i
= c1
.erase(c1
.cbegin() + P
);
68 assert(i
== c1
.begin() + P
);
69 assert(c1
.size() == c1_osize
- 1);
70 assert(static_cast<std::size_t>(distance(c1
.begin(), c1
.end())) == c1
.size());
73 for (; j
< P
; ++j
, ++i
)
75 for (++j
; static_cast<std::size_t>(j
) < c1_osize
; ++j
, ++i
)
81 testN(int start
, int N
)
83 int pstep
= std::max(N
/ std::max(std::min(N
, 10), 1), 1);
84 for (int p
= 0; p
< N
; p
+= pstep
)
86 C c1
= make
<C
>(N
, start
);
94 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
95 const int N
= sizeof(rng
)/sizeof(rng
[0]);
96 for (int i
= 0; i
< N
; ++i
)
97 for (int j
= 0; j
< N
; ++j
)
98 testN
<std::deque
<int> >(rng
[i
], rng
[j
]);
100 #if TEST_STD_VER >= 11
102 int rng
[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
103 const int N
= sizeof(rng
)/sizeof(rng
[0]);
104 for (int i
= 0; i
< N
; ++i
)
105 for (int j
= 0; j
< N
; ++j
)
106 testN
<std::deque
<int, min_allocator
<int>> >(rng
[i
], rng
[j
]);
110 #ifndef TEST_HAS_NO_EXCEPTIONS
112 // Throws: Nothing unless an exception is thrown by the assignment operator of T.
113 // (which includes move assignment)
115 Throws arr
[] = {1, 2, 3};
116 std::deque
<Throws
> v(arr
, arr
+3);
117 Throws::sThrows
= true;
121 assert(v
.size() == 0);