1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant//                     The LLVM Compiler Infrastructure
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// <deque>
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
12bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// void push_back(value_type&& v);
13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// void pop_back();
14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant// void pop_front();
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
16bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <deque>
17bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include <cassert>
18bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
19bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "../../../MoveOnly.h"
20061d0cc4db18d17bf01ed14c5db0be098205bd47Marshall Clow#include "min_allocator.h"
21bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
2273d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
23bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
24fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnanttemplate <class C>
25fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard HinnantC
26bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantmake(int size, int start = 0 )
27bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
28bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    const int b = 4096 / sizeof(int);
29bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int init = 0;
30bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    if (start > 0)
31bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
32bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        init = (start+1) / b + ((start+1) % b != 0);
33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        init *= b;
34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        --init;
35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
36fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    C c(init);
37bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (int i = 0; i < init-start; ++i)
38bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        c.pop_back();
39bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (int i = 0; i < size; ++i)
40bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        c.push_back(MoveOnly(i));
41bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (int i = 0; i < start; ++i)
42bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        c.pop_front();
43bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    return c;
44bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant};
45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
46fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnanttemplate <class C>
47bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantvoid test(int size)
48bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
49bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
50bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    const int N = sizeof(rng)/sizeof(rng[0]);
51bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (int j = 0; j < N; ++j)
52bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    {
53fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant        C c = make<C>(size, rng[j]);
54fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant        typename C::const_iterator it = c.begin();
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant        for (int i = 0; i < size; ++i, ++it)
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant            assert(*it == MoveOnly(i));
57bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    }
58bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
59bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
6073d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
62bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantint main()
63bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
6473d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
65fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    {
66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
67bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    const int N = sizeof(rng)/sizeof(rng[0]);
68bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant    for (int j = 0; j < N; ++j)
69fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant        test<std::deque<MoveOnly> >(rng[j]);
70fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    }
71fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant#if __cplusplus >= 201103L
72fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    {
73fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
74fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    const int N = sizeof(rng)/sizeof(rng[0]);
75fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    for (int j = 0; j < N; ++j)
76fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant        test<std::deque<MoveOnly, min_allocator<MoveOnly>> >(rng[j]);
77fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant    }
78fcd8db7133c56a5a627f3922ce4a180c12287dd9Howard Hinnant#endif
7973d21a4f0774d3fadab98e690619a359cfb160a3Howard Hinnant#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
80bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
81