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 // void pop_front() 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 <deque> 17 #include <cassert> 18 19 template <typename C> 20 void test(C c) 21 { 22 typename C::iterator it1 = c.begin() + 1; 23 typename C::iterator it2 = c.end() - 1; 24 25 c.pop_front(); 26 27 typename C::iterator it3 = c.begin(); 28 typename C::iterator it4 = c.end() - 1; 29 assert( it1 == it3); 30 assert( *it1 == *it3); 31 assert(&*it1 == &*it3); 32 assert( it2 == it4); 33 assert( *it2 == *it4); 34 assert(&*it2 == &*it4); 35 } 36 37 int main(int, char**) 38 { 39 std::deque<int> queue; 40 for (int i = 0; i < 20; ++i) 41 queue.push_back(i); 42 43 while (queue.size() > 1) 44 { 45 test(queue); 46 queue.pop_back(); 47 } 48 49 return 0; 50 } 51