insert_rvalue.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===//
2//
3// ��������������������The LLVM Compiler Infrastructure
4//
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// iterator insert (const_iterator p, value_type&& v);
13
14#include <deque>
15#include <cassert>
16
17#include "../../../MoveOnly.h"
18
19#ifdef _LIBCPP_MOVE
20
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(int P, std::deque<MoveOnly>& c1, int x)
44{
45    typedef std::deque<MoveOnly> C;
46    typedef C::iterator I;
47    typedef C::const_iterator CI;
48    std::size_t c1_osize = c1.size();
49    CI i = c1.insert(c1.begin() + P, MoveOnly(x));
50    assert(i == c1.begin() + P);
51    assert(c1.size() == c1_osize + 1);
52    assert(distance(c1.begin(), c1.end()) == c1.size());
53    i = c1.begin();
54    for (int j = 0; j < P; ++j, ++i)
55        assert(*i == MoveOnly(j));
56    assert(*i == MoveOnly(x));
57    ++i;
58    for (int j = P; j < c1_osize; ++j, ++i)
59        assert(*i == MoveOnly(j));
60}
61
62void
63testN(int start, int N)
64{
65    typedef std::deque<MoveOnly> C;
66    typedef C::iterator I;
67    typedef C::const_iterator CI;
68    for (int i = 0; i <= 3; ++i)
69    {
70        if (0 <= i && i <= N)
71        {
72            C c1 = make(N, start);
73            test(i, c1, -10);
74        }
75    }
76    for (int i = N/2-1; i <= N/2+1; ++i)
77    {
78        if (0 <= i && i <= N)
79        {
80            C c1 = make(N, start);
81            test(i, c1, -10);
82        }
83    }
84    for (int i = N - 3; i <= N; ++i)
85    {
86        if (0 <= i && i <= N)
87        {
88            C c1 = make(N, start);
89            test(i, c1, -10);
90        }
91    }
92}
93
94#endif
95
96int main()
97{
98#ifdef _LIBCPP_MOVE
99    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
100    const int N = sizeof(rng)/sizeof(rng[0]);
101    for (int i = 0; i < N; ++i)
102        for (int j = 0; j < N; ++j)
103            testN(rng[i], rng[j]);
104#endif
105}
106