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 | // <list> |
12 | |
13 | // template <class... Args> reference emplace_back(Args&&... args); |
14 | // return type is 'reference' in C++17; 'void' before |
15 | |
16 | #include <list> |
17 | #include <cassert> |
18 | |
19 | #include "test_macros.h" |
20 | #include "min_allocator.h" |
21 | |
22 | class A |
23 | { |
24 | int i_; |
25 | double d_; |
26 | |
27 | A(const A&); |
28 | A& operator=(const A&); |
29 | public: |
30 | A(int i, double d) |
31 | : i_(i), d_(d) {} |
32 | |
33 | int geti() const {return i_;} |
34 | double getd() const {return d_;} |
35 | }; |
36 | |
37 | int main(int, char**) |
38 | { |
39 | { |
40 | std::list<A> c; |
41 | #if TEST_STD_VER > 14 |
42 | A& r1 = c.emplace_back(2, 3.5); |
43 | assert(c.size() == 1); |
44 | assert(&r1 == &c.back()); |
45 | assert(c.front().geti() == 2); |
46 | assert(c.front().getd() == 3.5); |
47 | A& r2 = c.emplace_back(3, 4.5); |
48 | assert(c.size() == 2); |
49 | assert(&r2 == &c.back()); |
50 | #else |
51 | c.emplace_back(args: 2, args: 3.5); |
52 | assert(c.size() == 1); |
53 | assert(c.front().geti() == 2); |
54 | assert(c.front().getd() == 3.5); |
55 | c.emplace_back(args: 3, args: 4.5); |
56 | assert(c.size() == 2); |
57 | #endif |
58 | assert(c.front().geti() == 2); |
59 | assert(c.front().getd() == 3.5); |
60 | assert(c.back().geti() == 3); |
61 | assert(c.back().getd() == 4.5); |
62 | } |
63 | { |
64 | std::list<A, min_allocator<A>> c; |
65 | #if TEST_STD_VER > 14 |
66 | A& r1 = c.emplace_back(2, 3.5); |
67 | assert(c.size() == 1); |
68 | assert(&r1 == &c.back()); |
69 | assert(c.front().geti() == 2); |
70 | assert(c.front().getd() == 3.5); |
71 | A& r2 = c.emplace_back(3, 4.5); |
72 | assert(c.size() == 2); |
73 | assert(&r2 == &c.back()); |
74 | #else |
75 | c.emplace_back(2, 3.5); |
76 | assert(c.size() == 1); |
77 | assert(c.front().geti() == 2); |
78 | assert(c.front().getd() == 3.5); |
79 | c.emplace_back(3, 4.5); |
80 | assert(c.size() == 2); |
81 | #endif |
82 | assert(c.front().geti() == 2); |
83 | assert(c.front().getd() == 3.5); |
84 | assert(c.back().geti() == 3); |
85 | assert(c.back().getd() == 4.5); |
86 | } |
87 | |
88 | return 0; |
89 | } |
90 | |