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