Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <vector> |
| 11 | |
| 12 | // template <class... Args> iterator emplace(const_iterator pos, Args&&... args); |
| 13 | |
| 14 | #include <vector> |
| 15 | #include <cassert> |
| 16 | #include "../../../stack_allocator.h" |
| 17 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 18 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
| 20 | class A |
| 21 | { |
| 22 | int i_; |
| 23 | double d_; |
| 24 | |
| 25 | A(const A&); |
| 26 | A& operator=(const A&); |
| 27 | public: |
| 28 | A(int i, double d) |
| 29 | : i_(i), d_(d) {} |
| 30 | |
| 31 | A(A&& a) |
| 32 | : i_(a.i_), |
| 33 | d_(a.d_) |
| 34 | { |
| 35 | a.i_ = 0; |
| 36 | a.d_ = 0; |
| 37 | } |
| 38 | |
| 39 | A& operator=(A&& a) |
| 40 | { |
| 41 | i_ = a.i_; |
| 42 | d_ = a.d_; |
| 43 | a.i_ = 0; |
| 44 | a.d_ = 0; |
| 45 | return *this; |
| 46 | } |
| 47 | |
| 48 | int geti() const {return i_;} |
| 49 | double getd() const {return d_;} |
| 50 | }; |
| 51 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 52 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 53 | |
| 54 | int main() |
| 55 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 56 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 57 | { |
| 58 | std::vector<A> c; |
| 59 | std::vector<A>::iterator i = c.emplace(c.cbegin(), 2, 3.5); |
| 60 | assert(i == c.begin()); |
| 61 | assert(c.size() == 1); |
| 62 | assert(c.front().geti() == 2); |
| 63 | assert(c.front().getd() == 3.5); |
| 64 | i = c.emplace(c.cend(), 3, 4.5); |
| 65 | assert(i == c.end()-1); |
| 66 | assert(c.size() == 2); |
| 67 | assert(c.front().geti() == 2); |
| 68 | assert(c.front().getd() == 3.5); |
| 69 | assert(c.back().geti() == 3); |
| 70 | assert(c.back().getd() == 4.5); |
| 71 | i = c.emplace(c.cbegin()+1, 4, 6.5); |
| 72 | assert(i == c.begin()+1); |
| 73 | assert(c.size() == 3); |
| 74 | assert(c.front().geti() == 2); |
| 75 | assert(c.front().getd() == 3.5); |
| 76 | assert(c[1].geti() == 4); |
| 77 | assert(c[1].getd() == 6.5); |
| 78 | assert(c.back().geti() == 3); |
| 79 | assert(c.back().getd() == 4.5); |
| 80 | } |
| 81 | { |
| 82 | std::vector<A, stack_allocator<A, 7> > c; |
| 83 | std::vector<A, stack_allocator<A, 7> >::iterator i = c.emplace(c.cbegin(), 2, 3.5); |
| 84 | assert(i == c.begin()); |
| 85 | assert(c.size() == 1); |
| 86 | assert(c.front().geti() == 2); |
| 87 | assert(c.front().getd() == 3.5); |
| 88 | i = c.emplace(c.cend(), 3, 4.5); |
| 89 | assert(i == c.end()-1); |
| 90 | assert(c.size() == 2); |
| 91 | assert(c.front().geti() == 2); |
| 92 | assert(c.front().getd() == 3.5); |
| 93 | assert(c.back().geti() == 3); |
| 94 | assert(c.back().getd() == 4.5); |
| 95 | i = c.emplace(c.cbegin()+1, 4, 6.5); |
| 96 | assert(i == c.begin()+1); |
| 97 | assert(c.size() == 3); |
| 98 | assert(c.front().geti() == 2); |
| 99 | assert(c.front().getd() == 3.5); |
| 100 | assert(c[1].geti() == 4); |
| 101 | assert(c[1].getd() == 6.5); |
| 102 | assert(c.back().geti() == 3); |
| 103 | assert(c.back().getd() == 4.5); |
| 104 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 105 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 106 | } |