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 f, const_iterator l)
13 // Erasing items from the beginning or the end of a deque shall not invalidate iterators
14 // to items that were not erased.
17 #include "asan_testing.h"
22 #include "test_macros.h"
25 void del_at_start(C c
, std::size_t num
)
27 typename
C::iterator first
= c
.begin();
28 typename
C::iterator last
= first
+ num
;
29 typename
C::iterator it1
= last
;
30 typename
C::iterator it2
= c
.end() - 1;
32 c
.erase (first
, last
);
34 typename
C::iterator it3
= c
.begin();
35 typename
C::iterator it4
= c
.end() - 1;
37 assert( *it1
== *it3
);
38 assert(&*it1
== &*it3
);
40 assert( *it2
== *it4
);
41 assert(&*it2
== &*it4
);
42 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));
46 void del_at_end(C c
, std::size_t num
)
48 typename
C::iterator last
= c
.end();
49 typename
C::iterator first
= last
- num
;
50 typename
C::iterator it1
= c
.begin();
51 typename
C::iterator it2
= first
- 1;
53 c
.erase (first
, last
);
55 typename
C::iterator it3
= c
.begin();
56 typename
C::iterator it4
= c
.end() - 1;
58 assert( *it1
== *it3
);
59 assert(&*it1
== &*it3
);
61 assert( *it2
== *it4
);
62 assert(&*it2
== &*it4
);
63 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c
));
69 std::deque
<int> queue
;
70 for (int i
= 0; i
< 20; ++i
)
73 while (queue
.size() > 1)
75 for (std::size_t i
= 1; i
< queue
.size(); ++i
)
77 del_at_start(queue
, i
);
78 del_at_end (queue
, i
);