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 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <forward_list> |
| 11 | |
| 12 | // forward_list(forward_list&& x); |
| 13 | |
| 14 | #include <forward_list> |
| 15 | #include <cassert> |
| 16 | #include <iterator> |
| 17 | |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 18 | #include "test_allocator.h" |
Marshall Clow | df00d5e | 2015-01-28 21:22:53 +0000 | [diff] [blame] | 19 | #include "MoveOnly.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 20 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | |
| 22 | int main() |
| 23 | { |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 24 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 25 | { |
| 26 | typedef MoveOnly T; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 27 | typedef test_allocator<int> A; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 28 | typedef std::forward_list<T, A> C; |
| 29 | T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 30 | typedef std::move_iterator<T*> I; |
| 31 | C c0(I(std::begin(t)), I(std::end(t)), A(10)); |
| 32 | C c = std::move(c0); |
| 33 | unsigned n = 0; |
| 34 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 35 | assert(*i == n); |
| 36 | assert(n == std::end(t) - std::begin(t)); |
| 37 | assert(c0.empty()); |
| 38 | assert(c.get_allocator() == A(10)); |
| 39 | } |
| 40 | { |
| 41 | typedef MoveOnly T; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 42 | typedef other_allocator<int> A; |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | typedef std::forward_list<T, A> C; |
| 44 | T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 45 | typedef std::move_iterator<T*> I; |
| 46 | C c0(I(std::begin(t)), I(std::end(t)), A(10)); |
| 47 | C c = std::move(c0); |
| 48 | unsigned n = 0; |
| 49 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 50 | assert(*i == n); |
| 51 | assert(n == std::end(t) - std::begin(t)); |
| 52 | assert(c0.empty()); |
| 53 | assert(c.get_allocator() == A(10)); |
| 54 | } |
Howard Hinnant | 81381a9 | 2013-06-24 17:17:28 +0000 | [diff] [blame] | 55 | #if __cplusplus >= 201103L |
| 56 | { |
| 57 | typedef MoveOnly T; |
Dan Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | typedef min_allocator<int> A; |
Howard Hinnant | 81381a9 | 2013-06-24 17:17:28 +0000 | [diff] [blame] | 59 | typedef std::forward_list<T, A> C; |
| 60 | T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
| 61 | typedef std::move_iterator<T*> I; |
| 62 | C c0(I(std::begin(t)), I(std::end(t)), A()); |
| 63 | C c = std::move(c0); |
| 64 | unsigned n = 0; |
| 65 | for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) |
| 66 | assert(*i == n); |
| 67 | assert(n == std::end(t) - std::begin(t)); |
| 68 | assert(c0.empty()); |
| 69 | assert(c.get_allocator() == A()); |
| 70 | } |
| 71 | #endif |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 72 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 73 | } |