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