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// <vector> 11 12// template <class... Args> void emplace_back(Args&&... args); 13 14#include <vector> 15#include <cassert> 16#include "../../../stack_allocator.h" 17#include "min_allocator.h" 18 19#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 20 21class A 22{ 23 int i_; 24 double d_; 25 26 A(const A&); 27 A& operator=(const A&); 28public: 29 A(int i, double d) 30 : i_(i), d_(d) {} 31 32 A(A&& a) 33 : i_(a.i_), 34 d_(a.d_) 35 { 36 a.i_ = 0; 37 a.d_ = 0; 38 } 39 40 A& operator=(A&& a) 41 { 42 i_ = a.i_; 43 d_ = a.d_; 44 a.i_ = 0; 45 a.d_ = 0; 46 return *this; 47 } 48 49 int geti() const {return i_;} 50 double getd() const {return d_;} 51}; 52 53#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 54 55int main() 56{ 57#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 58 { 59 std::vector<A> c; 60 c.emplace_back(2, 3.5); 61 assert(c.size() == 1); 62 assert(c.front().geti() == 2); 63 assert(c.front().getd() == 3.5); 64 c.emplace_back(3, 4.5); 65 assert(c.size() == 2); 66 assert(c.front().geti() == 2); 67 assert(c.front().getd() == 3.5); 68 assert(c.back().geti() == 3); 69 assert(c.back().getd() == 4.5); 70 } 71 { 72 std::vector<A, stack_allocator<A, 4> > c; 73 c.emplace_back(2, 3.5); 74 assert(c.size() == 1); 75 assert(c.front().geti() == 2); 76 assert(c.front().getd() == 3.5); 77 c.emplace_back(3, 4.5); 78 assert(c.size() == 2); 79 assert(c.front().geti() == 2); 80 assert(c.front().getd() == 3.5); 81 assert(c.back().geti() == 3); 82 assert(c.back().getd() == 4.5); 83 } 84#if __cplusplus >= 201103L 85 { 86 std::vector<A, min_allocator<A>> c; 87 c.emplace_back(2, 3.5); 88 assert(c.size() == 1); 89 assert(c.front().geti() == 2); 90 assert(c.front().getd() == 3.5); 91 c.emplace_back(3, 4.5); 92 assert(c.size() == 2); 93 assert(c.front().geti() == 2); 94 assert(c.front().getd() == 3.5); 95 assert(c.back().geti() == 3); 96 assert(c.back().getd() == 4.5); 97 } 98#endif 99#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 100} 101