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 // <list>
11 
12 // template <class... Args> void emplace(const_iterator p, Args&&... args);
13 
14 #if _LIBCPP_DEBUG >= 1
15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16 #endif
17 
18 #include <list>
19 #include <cassert>
20 
21 #include "../../../min_allocator.h"
22 
23 class A
24 {
25     int i_;
26     double d_;
27 
28     A(const A&);
29     A& operator=(const A&);
30 public:
31     A(int i, double d)
32         : i_(i), d_(d) {}
33 
34     int geti() const {return i_;}
35     double getd() const {return d_;}
36 };
37 
38 int main()
39 {
40 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
41     {
42     std::list<A> c;
43     c.emplace(c.cbegin(), 2, 3.5);
44     assert(c.size() == 1);
45     assert(c.front().geti() == 2);
46     assert(c.front().getd() == 3.5);
47     c.emplace(c.cend(), 3, 4.5);
48     assert(c.size() == 2);
49     assert(c.front().geti() == 2);
50     assert(c.front().getd() == 3.5);
51     assert(c.back().geti() == 3);
52     assert(c.back().getd() == 4.5);
53     }
54 #if _LIBCPP_DEBUG >= 1
55     {
56         std::list<A> c1;
57         std::list<A> c2;
58         std::list<A>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
59         assert(false);
60     }
61 #endif
62 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
63 #if __cplusplus >= 201103L
64 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
65     {
66     std::list<A, min_allocator<A>> c;
67     c.emplace(c.cbegin(), 2, 3.5);
68     assert(c.size() == 1);
69     assert(c.front().geti() == 2);
70     assert(c.front().getd() == 3.5);
71     c.emplace(c.cend(), 3, 4.5);
72     assert(c.size() == 2);
73     assert(c.front().geti() == 2);
74     assert(c.front().getd() == 3.5);
75     assert(c.back().geti() == 3);
76     assert(c.back().getd() == 4.5);
77     }
78 #if _LIBCPP_DEBUG >= 1
79     {
80         std::list<A, min_allocator<A>> c1;
81         std::list<A, min_allocator<A>> c2;
82         std::list<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
83         assert(false);
84     }
85 #endif
86 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
87 #endif
88 }
89