1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <deque>
10
11// void assign(size_type n, const value_type& v);
12
13#include "asan_testing.h"
14#include <deque>
15#include <cassert>
16#include <cstddef>
17
18#include "test_macros.h"
19#include "test_iterators.h"
20#include "min_allocator.h"
21
22template <class C>
23C
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 C c(init, 0);
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(i);
39 for (int i = 0; i < start; ++i)
40 c.pop_front();
41 return c;
42}
43
44template <class C>
45void
46test(C& c1, int size, int v)
47{
48 typedef typename C::const_iterator CI;
49 c1.assign(size, v);
50 assert(c1.size() == static_cast<std::size_t>(size));
51 assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
52 LIBCPP_ASSERT(is_double_ended_contiguous_container_asan_correct(c1));
53 for (CI i = c1.begin(); i != c1.end(); ++i)
54 assert(*i == v);
55}
56
57template <class C>
58void
59testN(int start, int N, int M)
60{
61 C c1 = make<C>(N, start);
62 test(c1, M, -10);
63}
64
65int main(int, char**)
66{
67 {
68 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)
73 testN<std::deque<int> >(start: rng[i], N: rng[j], M: rng[k]);
74 }
75#if TEST_STD_VER >= 11
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
85
86 return 0;
87}
88

source code of libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp