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 | // <memory> |
| 11 | |
| 12 | // template <class OuterAlloc, class... InnerAllocs> |
| 13 | // class scoped_allocator_adaptor |
| 14 | |
| 15 | // template <class OuterA2> |
| 16 | // scoped_allocator_adaptor(scoped_allocator_adaptor<OuterA2, |
| 17 | // InnerAllocs...>&& other); |
| 18 | |
Howard Hinnant | e92c3d7 | 2010-08-19 18:39:17 +0000 | [diff] [blame] | 19 | #include <scoped_allocator> |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | #include <cassert> |
| 21 | |
| 22 | #include "../allocators.h" |
| 23 | |
| 24 | int main() |
| 25 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 26 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 27 | |
| 28 | { |
| 29 | typedef std::scoped_allocator_adaptor<A1<double>> B; |
| 30 | typedef std::scoped_allocator_adaptor<A1<int>> A; |
| 31 | B a1(A1<int>(3)); |
| 32 | A1<int>::copy_called = false; |
| 33 | A1<int>::move_called = false; |
| 34 | A a2 = std::move(a1); |
| 35 | assert(A1<int>::copy_called == false); |
| 36 | assert(A1<int>::move_called == true); |
| 37 | assert(a2 == a1); |
| 38 | } |
| 39 | { |
| 40 | typedef std::scoped_allocator_adaptor<A1<double>, A2<int>> B; |
| 41 | typedef std::scoped_allocator_adaptor<A1<int>, A2<int>> A; |
| 42 | B a1(A1<int>(4), A2<int>(5)); |
| 43 | A1<int>::copy_called = false; |
| 44 | A1<int>::move_called = false; |
| 45 | A2<int>::copy_called = false; |
| 46 | A2<int>::move_called = false; |
| 47 | A a2 = std::move(a1); |
| 48 | assert(A1<int>::copy_called == false); |
| 49 | assert(A1<int>::move_called == true); |
| 50 | assert(A2<int>::copy_called == false); |
| 51 | assert(A2<int>::move_called == true); |
| 52 | assert(a2 == a1); |
| 53 | } |
| 54 | { |
| 55 | typedef std::scoped_allocator_adaptor<A1<double>, A2<int>, A3<int>> B; |
| 56 | typedef std::scoped_allocator_adaptor<A1<int>, A2<int>, A3<int>> A; |
| 57 | B a1(A1<int>(4), A2<int>(5), A3<int>(6)); |
| 58 | A1<int>::copy_called = false; |
| 59 | A1<int>::move_called = false; |
| 60 | A2<int>::copy_called = false; |
| 61 | A2<int>::move_called = false; |
| 62 | A3<int>::copy_called = false; |
| 63 | A3<int>::move_called = false; |
| 64 | A a2 = std::move(a1); |
| 65 | assert(A1<int>::copy_called == false); |
| 66 | assert(A1<int>::move_called == true); |
| 67 | assert(A2<int>::copy_called == false); |
| 68 | assert(A2<int>::move_called == true); |
| 69 | assert(A3<int>::copy_called == false); |
| 70 | assert(A3<int>::move_called == true); |
| 71 | assert(a2 == a1); |
| 72 | } |
| 73 | |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 74 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 75 | } |