| 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> void emplace(const_iterator p, Args&&... args); |
| 14 | |
| 15 | #include <list> |
| 16 | #include <cassert> |
| 17 | |
| 18 | #include "test_macros.h" |
| 19 | #include "min_allocator.h" |
| 20 | |
| 21 | class A { |
| 22 | int i_; |
| 23 | double d_; |
| 24 | |
| 25 | A(const A&); |
| 26 | A& operator=(const A&); |
| 27 | |
| 28 | public: |
| 29 | A(int i, double d) : i_(i), d_(d) {} |
| 30 | |
| 31 | int geti() const { return i_; } |
| 32 | double getd() const { return d_; } |
| 33 | }; |
| 34 | |
| 35 | int main(int, char**) { |
| 36 | { |
| 37 | std::list<A> c; |
| 38 | c.emplace(position: c.cbegin(), args: 2, args: 3.5); |
| 39 | assert(c.size() == 1); |
| 40 | assert(c.front().geti() == 2); |
| 41 | assert(c.front().getd() == 3.5); |
| 42 | c.emplace(position: c.cend(), args: 3, args: 4.5); |
| 43 | assert(c.size() == 2); |
| 44 | assert(c.front().geti() == 2); |
| 45 | assert(c.front().getd() == 3.5); |
| 46 | assert(c.back().geti() == 3); |
| 47 | assert(c.back().getd() == 4.5); |
| 48 | } |
| 49 | { |
| 50 | std::list<A, min_allocator<A>> c; |
| 51 | c.emplace(c.cbegin(), 2, 3.5); |
| 52 | assert(c.size() == 1); |
| 53 | assert(c.front().geti() == 2); |
| 54 | assert(c.front().getd() == 3.5); |
| 55 | c.emplace(c.cend(), 3, 4.5); |
| 56 | assert(c.size() == 2); |
| 57 | assert(c.front().geti() == 2); |
| 58 | assert(c.front().getd() == 3.5); |
| 59 | assert(c.back().geti() == 3); |
| 60 | assert(c.back().getd() == 4.5); |
| 61 | } |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |