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 // void splice_after(const_iterator p, forward_list&& x);
13
14 #include <forward_list>
15 #include <cassert>
16 #include <iterator>
17
18 #include "min_allocator.h"
19
20 typedef int T;
21 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
22 const T t2[] = {10, 11, 12, 13, 14, 15};
23 const int size_t1 = std::end(t1) - std::begin(t1);
24 const int size_t2 = std::end(t2) - std::begin(t2);
25
26 template <class C>
27 void
testd(const C & c,int p,int l)28 testd(const C& c, int p, int l)
29 {
30 typename C::const_iterator i = c.begin();
31 int n1 = 0;
32 for (; n1 < p; ++n1, ++i)
33 assert(*i == t1[n1]);
34 for (int n2 = 0; n2 < l; ++n2, ++i)
35 assert(*i == t2[n2]);
36 for (; n1 < size_t1; ++n1, ++i)
37 assert(*i == t1[n1]);
38 assert(distance(c.begin(), c.end()) == size_t1 + l);
39 }
40
main()41 int main()
42 {
43 {
44 // splicing different containers
45 typedef std::forward_list<T> C;
46 for (int l = 0; l <= size_t2; ++l)
47 {
48 for (int p = 0; p <= size_t1; ++p)
49 {
50 C c1(std::begin(t1), std::end(t1));
51 C c2(t2, t2+l);
52
53 c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2));
54 testd(c1, p, l);
55 }
56 }
57 }
58 #if __cplusplus >= 201103L
59 {
60 // splicing different containers
61 typedef std::forward_list<T, min_allocator<T>> C;
62 for (int l = 0; l <= size_t2; ++l)
63 {
64 for (int p = 0; p <= size_t1; ++p)
65 {
66 C c1(std::begin(t1), std::end(t1));
67 C c2(t2, t2+l);
68
69 c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2));
70 testd(c1, p, l);
71 }
72 }
73 }
74 #endif
75 }
76