[lld][WebAssembly] Introduce Ctx::arg
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / erase_iter_iter.invalidation.pass.cpp
blob2920b7d83a1a643b6bda690a826c128dae86c006
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 //===----------------------------------------------------------------------===//
9 // <deque>
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"
18 #include <deque>
19 #include <cstdint>
20 #include <cassert>
22 #include "test_macros.h"
24 template <typename C>
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;
36 assert( it1 == it3);
37 assert( *it1 == *it3);
38 assert(&*it1 == &*it3);
39 assert( it2 == it4);
40 assert( *it2 == *it4);
41 assert(&*it2 == &*it4);
42 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
45 template <typename 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;
57 assert( it1 == it3);
58 assert( *it1 == *it3);
59 assert(&*it1 == &*it3);
60 assert( it2 == it4);
61 assert( *it2 == *it4);
62 assert(&*it2 == &*it4);
63 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));
67 int main(int, char**)
69 std::deque<int> queue;
70 for (int i = 0; i < 20; ++i)
71 queue.push_back(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);
80 queue.pop_back();
83 return 0;