blob: fd6dd6e4ab63b77a98384a2e2a55245aef840486 [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//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <deque>
11
12// void assign(size_type n, const value_type& v);
13
14#include <deque>
15#include <cassert>
16
Marshall Clow83e2c4d2013-01-05 03:21:01 +000017#include "test_iterators.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019
Howard Hinnantfcd8db72013-06-23 21:17:24 +000020template <class C>
21C
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022make(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 }
Howard Hinnantfcd8db72013-06-23 21:17:24 +000032 C c(init, 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000033 for (int i = 0; i < init-start; ++i)
34 c.pop_back();
35 for (int i = 0; i < size; ++i)
36 c.push_back(i);
37 for (int i = 0; i < start; ++i)
38 c.pop_front();
39 return c;
40};
41
Howard Hinnantfcd8db72013-06-23 21:17:24 +000042template <class C>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043void
Howard Hinnantfcd8db72013-06-23 21:17:24 +000044test(C& c1, int size, int v)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000045{
Howard Hinnantfcd8db72013-06-23 21:17:24 +000046 typedef typename C::const_iterator CI;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 std::size_t c1_osize = c1.size();
48 c1.assign(size, v);
49 assert(c1.size() == size);
50 assert(distance(c1.begin(), c1.end()) == c1.size());
51 for (CI i = c1.begin(); i != c1.end(); ++i)
52 assert(*i == v);
53}
54
Howard Hinnantfcd8db72013-06-23 21:17:24 +000055template <class C>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056void
57testN(int start, int N, int M)
58{
Howard Hinnantfcd8db72013-06-23 21:17:24 +000059 typedef typename C::iterator I;
60 typedef typename C::const_iterator CI;
61 C c1 = make<C>(N, start);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000062 test(c1, M, -10);
63}
64
65int main()
66{
Howard Hinnantfcd8db72013-06-23 21:17:24 +000067 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000068 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
69 const int N = sizeof(rng)/sizeof(rng[0]);
70 for (int i = 0; i < N; ++i)
71 for (int j = 0; j < N; ++j)
72 for (int k = 0; k < N; ++k)
Howard Hinnantfcd8db72013-06-23 21:17:24 +000073 testN<std::deque<int> >(rng[i], rng[j], rng[k]);
74 }
75#if __cplusplus >= 201103L
76 {
77 int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049};
78 const int N = sizeof(rng)/sizeof(rng[0]);
79 for (int i = 0; i < N; ++i)
80 for (int j = 0; j < N; ++j)
81 for (int k = 0; k < N; ++k)
82 testN<std::deque<int, min_allocator<int>> >(rng[i], rng[j], rng[k]);
83 }
84#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085}