[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / pop_back.pass.cpp
blob541adc2c5945dfcc54802e5cf1378bb3b5e9eaf1
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 //===----------------------------------------------------------------------===//
9 // <deque>
11 // void pop_back()
13 #include <deque>
14 #include <cassert>
15 #include <cstddef>
17 #include "test_macros.h"
18 #include "min_allocator.h"
20 template <class C>
22 make(int size, int start = 0 )
24 const int b = 4096 / sizeof(int);
25 int init = 0;
26 if (start > 0)
28 init = (start+1) / b + ((start+1) % b != 0);
29 init *= b;
30 --init;
32 C c(init, 0);
33 for (int i = 0; i < init-start; ++i)
34 c.pop_back();
35 for (int i = 0; i < size; ++i)
36 c.push_back(i);
37 for (int i = 0; i < start; ++i)
38 c.pop_front();
39 return c;
42 template <class C>
43 void
44 test(C& c1)
46 typedef typename C::iterator I;
47 std::size_t c1_osize = c1.size();
48 c1.pop_back();
49 assert(c1.size() == c1_osize - 1);
50 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
51 I i = c1.begin();
52 for (int j = 0; static_cast<std::size_t>(j) < c1.size(); ++j, ++i)
53 assert(*i == j);
56 template <class C>
57 void
58 testN(int start, int N)
60 if (N != 0)
62 C c1 = make<C>(N, start);
63 test(c1);
67 int main(int, char**)
70 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
71 const int N = sizeof(rng)/sizeof(rng[0]);
72 for (int i = 0; i < N; ++i)
73 for (int j = 0; j < N; ++j)
74 testN<std::deque<int> >(rng[i], rng[j]);
76 #if TEST_STD_VER >= 11
78 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
79 const int N = sizeof(rng)/sizeof(rng[0]);
80 for (int i = 0; i < N; ++i)
81 for (int j = 0; j < N; ++j)
82 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j]);
84 #endif
86 return 0;