brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · b538b0f Raw
72 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)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 <cassert>19 20#include "test_macros.h"21 22template <typename C>23void del_at_start(C c) {24  typename C::iterator first = c.begin();25  typename C::iterator it1   = first + 1;26  typename C::iterator it2   = c.end() - 1;27 28  c.erase(first);29 30  typename C::iterator it3 = c.begin();31  typename C::iterator it4 = c.end() - 1;32  assert(it1 == it3);33  assert(*it1 == *it3);34  assert(&*it1 == &*it3);35  assert(it2 == it4);36  assert(*it2 == *it4);37  assert(&*it2 == &*it4);38}39 40template <typename C>41void del_at_end(C c) {42  typename C::iterator first = c.end() - 1;43  typename C::iterator it1   = c.begin();44  typename C::iterator it2   = first - 1;45 46  c.erase(first);47 48  typename C::iterator it3 = c.begin();49  typename C::iterator it4 = c.end() - 1;50  assert(it1 == it3);51  assert(*it1 == *it3);52  assert(&*it1 == &*it3);53  assert(it2 == it4);54  assert(*it2 == *it4);55  assert(&*it2 == &*it4);56  LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c));57}58 59int main(int, char**) {60  std::deque<int> queue;61  for (int i = 0; i < 20; ++i)62    queue.push_back(i);63 64  while (queue.size() > 1) {65    del_at_start(queue);66    del_at_end(queue);67    queue.pop_back();68  }69 70  return 0;71}72