push_back_rvalue.pass.cpp revision b64f8b07c104c6cc986570ac8ee0ed16a9f23976
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// void push_back(value_type&& v);
13// void pop_back();
14// void pop_front();
15
16#include <deque>
17#include <cassert>
18
19#include "../../../MoveOnly.h"
20
21#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
22
23std::deque<MoveOnly>
24make(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    std::deque<MoveOnly> 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(MoveOnly(i));
39    for (int i = 0; i < start; ++i)
40        c.pop_front();
41    return c;
42};
43
44void test(int size)
45{
46    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049};
47    const int N = sizeof(rng)/sizeof(rng[0]);
48    for (int j = 0; j < N; ++j)
49    {
50        std::deque<MoveOnly> c = make(size, rng[j]);
51        std::deque<MoveOnly>::const_iterator it = c.begin();
52        for (int i = 0; i < size; ++i, ++it)
53            assert(*it == MoveOnly(i));
54    }
55}
56
57#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
58
59int main()
60{
61#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
62    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096};
63    const int N = sizeof(rng)/sizeof(rng[0]);
64    for (int j = 0; j < N; ++j)
65        test(rng[j]);
66#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
67}
68