]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / sequences / deque / deque.modifiers / emplace_front.pass.cpp
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 // UNSUPPORTED: c++98, c++03
11
12 // <deque>
13
14 // template <class... Args> reference emplace_front(Args&&... args);
15
16 #include <deque>
17 #include <cstddef>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "../../../Emplaceable.h"
22 #include "min_allocator.h"
23
24 template <class C>
25 C
26 make(int size, int start = 0 )
27 {
28     const int b = 4096 / sizeof(int);
29     int init = 0;
30     if (start > 0)
31     {
32         init = (start+1) / b + ((start+1) % b != 0);
33         init *= b;
34         --init;
35     }
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;
44 }
45
46 template <class C>
47 void
48 test(C& c1)
49 {
50     typedef typename C::iterator I;
51     typedef typename C::reference Ref;
52     std::size_t c1_osize = c1.size();
53     Ref res_ref = c1.emplace_front(Emplaceable(1, 2.5));
54     assert(c1.size() == c1_osize + 1);
55     assert(distance(c1.begin(), c1.end())
56                == static_cast<std::ptrdiff_t>(c1.size()));
57     I i = c1.begin();
58     assert(*i == Emplaceable(1, 2.5));
59     assert(&res_ref == &(*i));
60 }
61
62 template <class C>
63 void
64 testN(int start, int N)
65 {
66     C c1 = make<C>(N, start);
67     test(c1);
68 }
69
70
71 int main()
72 {
73     {
74     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
75     const int N = sizeof(rng)/sizeof(rng[0]);
76     for (int i = 0; i < N; ++i)
77         for (int j = 0; j < N; ++j)
78             testN<std::deque<Emplaceable> >(rng[i], rng[j]);
79     }
80     {
81     int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
82     const int N = sizeof(rng)/sizeof(rng[0]);
83     for (int i = 0; i < N; ++i)
84         for (int j = 0; j < N; ++j)
85             testN<std::deque<Emplaceable, min_allocator<Emplaceable>> >(rng[i], rng[j]);
86     }
87 }