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