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

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