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 // <deque> 10 11 // iterator erase(const_iterator f) 12 13 // Erasing items from the beginning or the end of a deque shall not invalidate iterators 14 // to items that were not erased. 15 16 #include "asan_testing.h" 17 #include <deque> 18 #include <cassert> 19 20 #include "test_macros.h" 21 22 template <typename C> del_at_start(C c)23void del_at_start(C c) 24 { 25 typename C::iterator first = c.begin(); 26 typename C::iterator it1 = first + 1; 27 typename C::iterator it2 = c.end() - 1; 28 29 c.erase (first); 30 31 typename C::iterator it3 = c.begin(); 32 typename C::iterator it4 = c.end() - 1; 33 assert( it1 == it3); 34 assert( *it1 == *it3); 35 assert(&*it1 == &*it3); 36 assert( it2 == it4); 37 assert( *it2 == *it4); 38 assert(&*it2 == &*it4); 39 } 40 41 template <typename C> del_at_end(C c)42void del_at_end(C c) 43 { 44 typename C::iterator first = c.end() - 1; 45 typename C::iterator it1 = c.begin(); 46 typename C::iterator it2 = first - 1; 47 48 c.erase (first); 49 50 typename C::iterator it3 = c.begin(); 51 typename C::iterator it4 = c.end() - 1; 52 assert( it1 == it3); 53 assert( *it1 == *it3); 54 assert(&*it1 == &*it3); 55 assert( it2 == it4); 56 assert( *it2 == *it4); 57 assert(&*it2 == &*it4); 58 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c)); 59 } 60 main(int,char **)61int main(int, char**) 62 { 63 std::deque<int> queue; 64 for (int i = 0; i < 20; ++i) 65 queue.push_back(i); 66 67 while (queue.size() > 1) 68 { 69 del_at_start(queue); 70 del_at_end(queue); 71 queue.pop_back(); 72 } 73 74 return 0; 75 } 76