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> void emplace_back(Args&&... args);
13 
14 #include <deque>
15 #include <cassert>
16 
17 #include "../../../Emplaceable.h"
18 #include "min_allocator.h"
19 #include "test_allocator.h"
20 
21 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
22 
23 template <class C>
24 C
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
47 test(C& c1)
48 {
49     typedef typename C::iterator I;
50     std::size_t c1_osize = c1.size();
51     c1.emplace_back(Emplaceable(1, 2.5));
52     assert(c1.size() == c1_osize + 1);
53     assert(distance(c1.begin(), c1.end()) == c1.size());
54     I i = c1.end();
55     assert(*--i == Emplaceable(1, 2.5));
56 }
57 
58 template <class C>
59 void
60 testN(int start, int N)
61 {
62     C c1 = make<C>(N, start);
63     test(c1);
64 }
65 
66 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
67 
68 int main()
69 {
70 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
71     {
72     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
73     const int N = sizeof(rng)/sizeof(rng[0]);
74     for (int i = 0; i < N; ++i)
75         for (int j = 0; j < N; ++j)
76             testN<std::deque<Emplaceable> >(rng[i], rng[j]);
77     }
78 #if TEST_STD_VER >= 11
79     {
80     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
81     const int N = sizeof(rng)/sizeof(rng[0]);
82     for (int i = 0; i < N; ++i)
83         for (int j = 0; j < N; ++j)
84             testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
85     }
86     {
87         std::deque<Tag_X, TaggingAllocator<Tag_X>> c;
88         c.emplace_back();
89         assert(c.size() == 1);
90         c.emplace_back(1, 2, 3);
91         assert(c.size() == 2);
92         c.emplace_front();
93         assert(c.size() == 3);
94         c.emplace_front(1, 2, 3);
95         assert(c.size() == 4);
96     }
97 #endif
98 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
99 }
100