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// UNSUPPORTED: c++03
10
11// <forward_list>
12
13// void assign(initializer_list<value_type> il);
14
15#include <forward_list>
16#include <cassert>
17#include <iterator>
18
19#include "test_macros.h"
20#include "min_allocator.h"
21
22int main(int, char**)
23{
24 {
25 typedef int T;
26 typedef std::forward_list<T> C;
27 const T t1[] = {10, 11, 12, 13};
28 C c(std::begin(arr: t1), std::end(arr: t1));
29 c.assign(il: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
30 int n = 0;
31 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
32 assert(*i == n);
33 assert(n == 10);
34 }
35 {
36 typedef int T;
37 typedef std::forward_list<T> C;
38 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
39 C c(std::begin(arr: t1), std::end(arr: t1));
40 c.assign(il: {10, 11, 12, 13});
41 int n = 0;
42 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
43 assert(*i == 10+n);
44 assert(n == 4);
45 }
46 {
47 typedef int T;
48 typedef std::forward_list<T, min_allocator<T>> C;
49 const T t1[] = {10, 11, 12, 13};
50 C c(std::begin(arr: t1), std::end(arr: t1));
51 c.assign({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
52 int n = 0;
53 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
54 assert(*i == n);
55 assert(n == 10);
56 }
57 {
58 typedef int T;
59 typedef std::forward_list<T, min_allocator<T>> C;
60 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
61 C c(std::begin(arr: t1), std::end(arr: t1));
62 c.assign({10, 11, 12, 13});
63 int n = 0;
64 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
65 assert(*i == 10+n);
66 assert(n == 4);
67 }
68
69 return 0;
70}
71

source code of libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp