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 // UNSUPPORTED: c++98, c++03
15 
16 #include <deque>
17 #include <cassert>
18 
19 #include "../../../Emplaceable.h"
20 #include "min_allocator.h"
21 
22 
23 template <class C>
24 C
make(int size,int start=0)25 make(int size, int start = 0 )
26 {
27     const int b = 4096 / sizeof(int);
28     int init = 0;
29     if (start > 0)
30     {
31         init = (start+1) / b + ((start+1) % b != 0);
32         init *= b;
33         --init;
34     }
35     C c(init);
36     for (int i = 0; i < init-start; ++i)
37         c.pop_back();
38     for (int i = 0; i < size; ++i)
39         c.push_back(Emplaceable());
40     for (int i = 0; i < start; ++i)
41         c.pop_front();
42     return c;
43 }
44 
45 template <class C>
46 void
test(int P,C & c1)47 test(int P, C& c1)
48 {
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
testN(int start,int N)60 testN(int start, int N)
61 {
62     for (int i = 0; i <= 3; ++i)
63     {
64         if (0 <= i && i <= N)
65         {
66             C c1 = make<C>(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<C>(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<C>(N, start);
83             test(i, c1);
84         }
85     }
86 }
87 
88 
main()89 int main()
90 {
91     {
92     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
93     const int N = sizeof(rng)/sizeof(rng[0]);
94     for (int i = 0; i < N; ++i)
95         for (int j = 0; j < N; ++j)
96             testN<std::deque<Emplaceable> >(rng[i], rng[j]);
97     }
98     {
99     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
100     const int N = sizeof(rng)/sizeof(rng[0]);
101     for (int i = 0; i < N; ++i)
102         for (int j = 0; j < N; ++j)
103             testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
104     }
105 }
106