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 #include "../../../min_allocator.h"
19 
20 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
21 
22 template <class C>
23 C
24 make(int size, int start = 0 )
25 {
26     const int b = 4096 / sizeof(int);
27     int init = 0;
28     if (start > 0)
29     {
30         init = (start+1) / b + ((start+1) % b != 0);
31         init *= b;
32         --init;
33     }
34     C c(init);
35     for (int i = 0; i < init-start; ++i)
36         c.pop_back();
37     for (int i = 0; i < size; ++i)
38         c.push_back(Emplaceable());
39     for (int i = 0; i < start; ++i)
40         c.pop_front();
41     return c;
42 };
43 
44 template <class C>
45 void
46 test(int P, C& c1)
47 {
48     typedef typename C::iterator I;
49     typedef typename C::const_iterator CI;
50     std::size_t c1_osize = c1.size();
51     CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5));
52     assert(i == c1.begin() + P);
53     assert(c1.size() == c1_osize + 1);
54     assert(distance(c1.begin(), c1.end()) == c1.size());
55     assert(*i == Emplaceable(1, 2.5));
56 }
57 
58 template <class C>
59 void
60 testN(int start, int N)
61 {
62     typedef typename C::iterator I;
63     typedef typename C::const_iterator CI;
64     for (int i = 0; i <= 3; ++i)
65     {
66         if (0 <= i && i <= N)
67         {
68             C c1 = make<C>(N, start);
69             test(i, c1);
70         }
71     }
72     for (int i = N/2-1; i <= N/2+1; ++i)
73     {
74         if (0 <= i && i <= N)
75         {
76             C c1 = make<C>(N, start);
77             test(i, c1);
78         }
79     }
80     for (int i = N - 3; i <= N; ++i)
81     {
82         if (0 <= i && i <= N)
83         {
84             C c1 = make<C>(N, start);
85             test(i, c1);
86         }
87     }
88 }
89 
90 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
91 
92 int main()
93 {
94 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
95     {
96     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
97     const int N = sizeof(rng)/sizeof(rng[0]);
98     for (int i = 0; i < N; ++i)
99         for (int j = 0; j < N; ++j)
100             testN<std::deque<Emplaceable> >(rng[i], rng[j]);
101     }
102 #if __cplusplus >= 201103L
103     {
104     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
105     const int N = sizeof(rng)/sizeof(rng[0]);
106     for (int i = 0; i < N; ++i)
107         for (int j = 0; j < N; ++j)
108             testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
109     }
110 #endif
111 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
112 }
113