blob: 8341f7ba0cb22b8f2159038222d9b5dc259fb01f [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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 Clow1b921882013-12-03 00:18:10 +000018#include "test_allocator.h"
Marshall Clowdf00d5e2015-01-28 21:22:53 +000019#include "MoveOnly.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000020#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021
22int main()
23{
Howard Hinnant73d21a42010-09-04 23:28:19 +000024#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000025 {
26 typedef MoveOnly T;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070027 typedef test_allocator<int> A;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000028 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 Albert1d4a1ed2016-05-25 22:36:09 -070042 typedef other_allocator<int> A;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000043 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 Hinnant81381a92013-06-24 17:17:28 +000055#if __cplusplus >= 201103L
56 {
57 typedef MoveOnly T;
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058 typedef min_allocator<int> A;
Howard Hinnant81381a92013-06-24 17:17:28 +000059 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 Hinnant73d21a42010-09-04 23:28:19 +000072#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000073}