assign_iter_iter.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
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// template <class InputIterator>
13//   void assign(InputIterator f, InputIterator l);
14
15#include <deque>
16#include <cassert>
17
18#include "../../../iterators.h"
19
20std::deque<int>
21make(int size, int start = 0 )
22{
23    const int b = 4096 / sizeof(int);
24    int init = 0;
25    if (start > 0)
26    {
27        init = (start+1) / b + ((start+1) % b != 0);
28        init *= b;
29        --init;
30    }
31    std::deque<int> c(init, 0);
32    for (int i = 0; i < init-start; ++i)
33        c.pop_back();
34    for (int i = 0; i < size; ++i)
35        c.push_back(i);
36    for (int i = 0; i < start; ++i)
37        c.pop_front();
38    return c;
39};
40
41void
42test(std::deque<int>& c1, const std::deque<int>& c2)
43{
44    std::size_t c1_osize = c1.size();
45    c1.assign(c2.begin(), c2.end());
46    assert(distance(c1.begin(), c1.end()) == c1.size());
47    assert(c1 == c2);
48}
49
50void
51testN(int start, int N, int M)
52{
53    typedef std::deque<int> C;
54    typedef C::iterator I;
55    typedef C::const_iterator CI;
56    C c1 = make(N, start);
57    C c2 = make(M);
58    test(c1, c2);
59}
60
61void
62testI(std::deque<int>& c1, const std::deque<int>& c2)
63{
64    typedef std::deque<int> C;
65    typedef C::const_iterator CI;
66    typedef input_iterator<CI> ICI;
67    std::size_t c1_osize = c1.size();
68    c1.assign(ICI(c2.begin()), ICI(c2.end()));
69    assert(distance(c1.begin(), c1.end()) == c1.size());
70    assert(c1 == c2);
71}
72
73void
74testNI(int start, int N, int M)
75{
76    typedef std::deque<int> C;
77    typedef C::iterator I;
78    typedef C::const_iterator CI;
79    C c1 = make(N, start);
80    C c2 = make(M);
81    testI(c1, c2);
82}
83
84int main()
85{
86    int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
87    const int N = sizeof(rng)/sizeof(rng[0]);
88    for (int i = 0; i < N; ++i)
89        for (int j = 0; j < N; ++j)
90            for (int k = 0; k < N; ++k)
91                testN(rng[i], rng[j], rng[k]);
92    testNI(1500, 2000, 1000);
93}
94