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 | // template <class... Args> |
14 | // iterator emplace_after(const_iterator p, Args&&... args); |
15 | |
16 | #include <forward_list> |
17 | #include <cassert> |
18 | |
19 | #include "test_macros.h" |
20 | #include "../../../Emplaceable.h" |
21 | #include "min_allocator.h" |
22 | |
23 | int main(int, char**) |
24 | { |
25 | { |
26 | typedef Emplaceable T; |
27 | typedef std::forward_list<T> C; |
28 | typedef C::iterator I; |
29 | C c; |
30 | I i = c.emplace_after(pos: c.cbefore_begin()); |
31 | assert(i == c.begin()); |
32 | assert(c.front() == Emplaceable()); |
33 | assert(std::distance(c.begin(), c.end()) == 1); |
34 | |
35 | i = c.emplace_after(pos: c.cbegin(), args: 1, args: 2.5); |
36 | assert(i == std::next(c.begin())); |
37 | assert(c.front() == Emplaceable()); |
38 | assert(*std::next(c.begin()) == Emplaceable(1, 2.5)); |
39 | assert(std::distance(c.begin(), c.end()) == 2); |
40 | |
41 | i = c.emplace_after(pos: std::next(x: c.cbegin()), args: 2, args: 3.5); |
42 | assert(i == std::next(c.begin(), 2)); |
43 | assert(c.front() == Emplaceable()); |
44 | assert(*std::next(c.begin()) == Emplaceable(1, 2.5)); |
45 | assert(*std::next(c.begin(), 2) == Emplaceable(2, 3.5)); |
46 | assert(std::distance(c.begin(), c.end()) == 3); |
47 | |
48 | i = c.emplace_after(pos: c.cbegin(), args: 3, args: 4.5); |
49 | assert(i == std::next(c.begin())); |
50 | assert(c.front() == Emplaceable()); |
51 | assert(*std::next(c.begin(), 1) == Emplaceable(3, 4.5)); |
52 | assert(*std::next(c.begin(), 2) == Emplaceable(1, 2.5)); |
53 | assert(*std::next(c.begin(), 3) == Emplaceable(2, 3.5)); |
54 | assert(std::distance(c.begin(), c.end()) == 4); |
55 | } |
56 | { |
57 | typedef Emplaceable T; |
58 | typedef std::forward_list<T, min_allocator<T>> C; |
59 | typedef C::iterator I; |
60 | C c; |
61 | I i = c.emplace_after(c.cbefore_begin()); |
62 | assert(i == c.begin()); |
63 | assert(c.front() == Emplaceable()); |
64 | assert(std::distance(c.begin(), c.end()) == 1); |
65 | |
66 | i = c.emplace_after(c.cbegin(), 1, 2.5); |
67 | assert(i == std::next(c.begin())); |
68 | assert(c.front() == Emplaceable()); |
69 | assert(*std::next(c.begin()) == Emplaceable(1, 2.5)); |
70 | assert(std::distance(c.begin(), c.end()) == 2); |
71 | |
72 | i = c.emplace_after(std::next(c.cbegin()), 2, 3.5); |
73 | assert(i == std::next(c.begin(), 2)); |
74 | assert(c.front() == Emplaceable()); |
75 | assert(*std::next(c.begin()) == Emplaceable(1, 2.5)); |
76 | assert(*std::next(c.begin(), 2) == Emplaceable(2, 3.5)); |
77 | assert(std::distance(c.begin(), c.end()) == 3); |
78 | |
79 | i = c.emplace_after(c.cbegin(), 3, 4.5); |
80 | assert(i == std::next(c.begin())); |
81 | assert(c.front() == Emplaceable()); |
82 | assert(*std::next(c.begin(), 1) == Emplaceable(3, 4.5)); |
83 | assert(*std::next(c.begin(), 2) == Emplaceable(1, 2.5)); |
84 | assert(*std::next(c.begin(), 3) == Emplaceable(2, 3.5)); |
85 | assert(std::distance(c.begin(), c.end()) == 4); |
86 | } |
87 | |
88 | return 0; |
89 | } |
90 | |