blob: 86c28f0f47a6dfe0dac33cb77cb54e8a2f95feed [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <deque>
11
12// void push_front(value_type&& v);
13
14#include <deque>
15#include <cassert>
16
17#include "../../../MoveOnly.h"
18
Howard Hinnant73d21a42010-09-04 23:28:19 +000019#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020
21std::deque<MoveOnly>
22make(int size, int start = 0 )
23{
24 const int b = 4096 / sizeof(int);
25 int init = 0;
26 if (start > 0)
27 {
28 init = (start+1) / b + ((start+1) % b != 0);
29 init *= b;
30 --init;
31 }
32 std::deque<MoveOnly> c(init);
33 for (int i = 0; i < init-start; ++i)
34 c.pop_back();
35 for (int i = 0; i < size; ++i)
36 c.push_back(MoveOnly(i));
37 for (int i = 0; i < start; ++i)
38 c.pop_front();
39 return c;
40};
41
42void
43test(std::deque<MoveOnly>& c1, int x)
44{
45 typedef std::deque<MoveOnly> C;
46 typedef C::iterator I;
47 std::size_t c1_osize = c1.size();
48 c1.push_front(MoveOnly(x));
49 assert(c1.size() == c1_osize + 1);
50 assert(distance(c1.begin(), c1.end()) == c1.size());
51 I i = c1.begin();
52 assert(*i == MoveOnly(x));
53 ++i;
54 for (int j = 0; j < c1_osize; ++j, ++i)
55 assert(*i == MoveOnly(j));
56}
57
58void
59testN(int start, int N)
60{
61 typedef std::deque<MoveOnly> C;
62 C c1 = make(N, start);
63 test(c1, -10);
64}
65
Howard Hinnant73d21a42010-09-04 23:28:19 +000066#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000067
68int main()
69{
Howard Hinnant73d21a42010-09-04 23:28:19 +000070#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000071 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
72 const int N = sizeof(rng)/sizeof(rng[0]);
73 for (int i = 0; i < N; ++i)
74 for (int j = 0; j < N; ++j)
75 testN(rng[i], rng[j]);
Howard Hinnant73d21a42010-09-04 23:28:19 +000076#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000077}