1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <forward_list>
11
12 // template <class InputIterator>
13 // void assign(InputIterator first, InputIterator last);
14
15 #include <forward_list>
16 #include <cassert>
17 #include <iterator>
18
19 #include "test_iterators.h"
20 #include "min_allocator.h"
21
main()22 int main()
23 {
24 {
25 typedef int T;
26 typedef std::forward_list<T> C;
27 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
28 const T t1[] = {10, 11, 12, 13};
29 C c(std::begin(t1), std::end(t1));
30 typedef input_iterator<const T*> I;
31 c.assign(I(std::begin(t0)), I(std::end(t0)));
32 int n = 0;
33 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
34 assert(*i == n);
35 assert(n == 10);
36 }
37 {
38 typedef int T;
39 typedef std::forward_list<T> C;
40 const T t0[] = {10, 11, 12, 13};
41 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
42 C c(std::begin(t1), std::end(t1));
43 typedef input_iterator<const T*> I;
44 c.assign(I(std::begin(t0)), I(std::end(t0)));
45 int n = 0;
46 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
47 assert(*i == 10+n);
48 assert(n == 4);
49 }
50 #if __cplusplus >= 201103L
51 {
52 typedef int T;
53 typedef std::forward_list<T, min_allocator<T>> C;
54 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
55 const T t1[] = {10, 11, 12, 13};
56 C c(std::begin(t1), std::end(t1));
57 typedef input_iterator<const T*> I;
58 c.assign(I(std::begin(t0)), I(std::end(t0)));
59 int n = 0;
60 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
61 assert(*i == n);
62 assert(n == 10);
63 }
64 {
65 typedef int T;
66 typedef std::forward_list<T, min_allocator<T>> C;
67 const T t0[] = {10, 11, 12, 13};
68 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
69 C c(std::begin(t1), std::end(t1));
70 typedef input_iterator<const T*> I;
71 c.assign(I(std::begin(t0)), I(std::end(t0)));
72 int n = 0;
73 for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
74 assert(*i == 10+n);
75 assert(n == 4);
76 }
77 #endif
78 }
79