[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / sequences / deque / deque.modifiers / emplace.pass.cpp
blobdea23d91a43c84abc8b3d08958f63319c6230262
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 // template <class... Args> iterator emplace(const_iterator p, Args&&... args);
13 // UNSUPPORTED: c++03
15 #include <deque>
16 #include <cassert>
17 #include <cstddef>
19 #include "test_macros.h"
20 #include "../../../Emplaceable.h"
21 #include "min_allocator.h"
24 template <class C>
26 make(int size, int start = 0 )
28 const int b = 4096 / sizeof(int);
29 int init = 0;
30 if (start > 0)
32 init = (start+1) / b + ((start+1) % b != 0);
33 init *= b;
34 --init;
36 C c(init);
37 for (int i = 0; i < init-start; ++i)
38 c.pop_back();
39 for (int i = 0; i < size; ++i)
40 c.push_back(Emplaceable());
41 for (int i = 0; i < start; ++i)
42 c.pop_front();
43 return c;
46 template <class C>
47 void
48 test(int P, C& c1)
50 typedef typename C::const_iterator CI;
51 std::size_t c1_osize = c1.size();
52 CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5));
53 assert(i == c1.begin() + P);
54 assert(c1.size() == c1_osize + 1);
55 assert(static_cast<std::size_t>(distance(c1.begin(), c1.end())) == c1.size());
56 assert(*i == Emplaceable(1, 2.5));
59 template <class C>
60 void
61 testN(int start, int N)
63 for (int i = 0; i <= 3; ++i)
65 if (0 <= i && i <= N)
67 C c1 = make<C>(N, start);
68 test(i, c1);
71 for (int i = N/2-1; i <= N/2+1; ++i)
73 if (0 <= i && i <= N)
75 C c1 = make<C>(N, start);
76 test(i, c1);
79 for (int i = N - 3; i <= N; ++i)
81 if (0 <= i && i <= N)
83 C c1 = make<C>(N, start);
84 test(i, c1);
90 int main(int, char**)
93 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
94 const int N = sizeof(rng)/sizeof(rng[0]);
95 for (int i = 0; i < N; ++i)
96 for (int j = 0; j < N; ++j)
97 testN<std::deque<Emplaceable> >(rng[i], rng[j]);
100 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
101 const int N = sizeof(rng)/sizeof(rng[0]);
102 for (int i = 0; i < N; ++i)
103 for (int j = 0; j < N; ++j)
104 testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
107 return 0;