blob: 197fa1381e67ae465bb0de12fb5c9b2c62cfc625 [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//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <forward_list>
11
12// forward_list(forward_list&& x, const allocator_type& a);
13
14#include <forward_list>
15#include <cassert>
16#include <iterator>
17
18#include "../../../test_allocator.h"
19#include "../../../MoveOnly.h"
20
21int main()
22{
Howard Hinnant73d21a42010-09-04 23:28:19 +000023#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024 {
25 typedef MoveOnly T;
26 typedef test_allocator<int> A;
27 typedef std::forward_list<T, A> C;
28 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
29 typedef std::move_iterator<T*> I;
30 C c0(I(std::begin(t)), I(std::end(t)), A(10));
31 C c(std::move(c0), A(10));
32 unsigned n = 0;
33 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
34 assert(*i == n);
35 assert(n == std::end(t) - std::begin(t));
36 assert(c0.empty());
37 assert(c.get_allocator() == A(10));
38 }
39 {
40 typedef MoveOnly T;
41 typedef test_allocator<int> A;
42 typedef std::forward_list<T, A> C;
43 T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
44 typedef std::move_iterator<T*> I;
45 C c0(I(std::begin(t)), I(std::end(t)), A(10));
46 C c(std::move(c0), A(9));
47 unsigned n = 0;
48 for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
49 assert(*i == n);
50 assert(n == std::end(t) - std::begin(t));
51 assert(!c0.empty());
52 assert(c.get_allocator() == A(9));
53 }
Howard Hinnant73d21a42010-09-04 23:28:19 +000054#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000055}