1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <deque>
11
12 // template <class... Args> iterator emplace(const_iterator p, Args&&... args);
13
14 #include <deque>
15 #include <cassert>
16
17 #include "../../../Emplaceable.h"
18
19 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
20
21 std::deque<Emplaceable>
make(int size,int start=0)22 make(int size, int start = 0 )
23 {
24 const int b = 4096 / sizeof(int);
25 int init = 0;
26 if (start > 0)
27 {
28 init = (start+1) / b + ((start+1) % b != 0);
29 init *= b;
30 --init;
31 }
32 std::deque<Emplaceable> c(init);
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(Emplaceable());
37 for (int i = 0; i < start; ++i)
38 c.pop_front();
39 return c;
40 };
41
42 void
test(int P,std::deque<Emplaceable> & c1)43 test(int P, std::deque<Emplaceable>& c1)
44 {
45 typedef std::deque<Emplaceable> C;
46 typedef C::iterator I;
47 typedef C::const_iterator CI;
48 std::size_t c1_osize = c1.size();
49 CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5));
50 assert(i == c1.begin() + P);
51 assert(c1.size() == c1_osize + 1);
52 assert(distance(c1.begin(), c1.end()) == c1.size());
53 assert(*i == Emplaceable(1, 2.5));
54 }
55
56 void
testN(int start,int N)57 testN(int start, int N)
58 {
59 typedef std::deque<Emplaceable> C;
60 typedef C::iterator I;
61 typedef C::const_iterator CI;
62 for (int i = 0; i <= 3; ++i)
63 {
64 if (0 <= i && i <= N)
65 {
66 C c1 = make(N, start);
67 test(i, c1);
68 }
69 }
70 for (int i = N/2-1; i <= N/2+1; ++i)
71 {
72 if (0 <= i && i <= N)
73 {
74 C c1 = make(N, start);
75 test(i, c1);
76 }
77 }
78 for (int i = N - 3; i <= N; ++i)
79 {
80 if (0 <= i && i <= N)
81 {
82 C c1 = make(N, start);
83 test(i, c1);
84 }
85 }
86 }
87
88 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
89
main()90 int main()
91 {
92 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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(rng[i], rng[j]);
98 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
99 }
100