1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11
12// vector(vector&& c);
13
14#include <vector>
15#include <cassert>
16#include "../../../MoveOnly.h"
17#include "test_allocator.h"
18#include "min_allocator.h"
19
20int main()
21{
22#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
23    {
24        std::vector<MoveOnly, test_allocator<MoveOnly> > l(test_allocator<MoveOnly>(5));
25        std::vector<MoveOnly, test_allocator<MoveOnly> > lo(test_allocator<MoveOnly>(5));
26        for (int i = 1; i <= 3; ++i)
27        {
28            l.push_back(i);
29            lo.push_back(i);
30        }
31        std::vector<MoveOnly, test_allocator<MoveOnly> > l2 = std::move(l);
32        assert(l2 == lo);
33        assert(l.empty());
34        assert(l2.get_allocator() == lo.get_allocator());
35    }
36    {
37        std::vector<MoveOnly, other_allocator<MoveOnly> > l(other_allocator<MoveOnly>(5));
38        std::vector<MoveOnly, other_allocator<MoveOnly> > lo(other_allocator<MoveOnly>(5));
39        for (int i = 1; i <= 3; ++i)
40        {
41            l.push_back(i);
42            lo.push_back(i);
43        }
44        std::vector<MoveOnly, other_allocator<MoveOnly> > l2 = std::move(l);
45        assert(l2 == lo);
46        assert(l.empty());
47        assert(l2.get_allocator() == lo.get_allocator());
48    }
49    {
50        int a1[] = {1, 3, 7, 9, 10};
51        std::vector<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
52        std::vector<int>::const_iterator i = c1.begin();
53        std::vector<int> c2 = std::move(c1);
54        std::vector<int>::iterator j = c2.erase(i);
55        assert(*j == 3);
56    }
57#if __cplusplus >= 201103L
58    {
59        std::vector<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
60        std::vector<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
61        for (int i = 1; i <= 3; ++i)
62        {
63            l.push_back(i);
64            lo.push_back(i);
65        }
66        std::vector<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
67        assert(l2 == lo);
68        assert(l.empty());
69        assert(l2.get_allocator() == lo.get_allocator());
70    }
71    {
72        int a1[] = {1, 3, 7, 9, 10};
73        std::vector<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
74        std::vector<int, min_allocator<int>>::const_iterator i = c1.begin();
75        std::vector<int, min_allocator<int>> c2 = std::move(c1);
76        std::vector<int, min_allocator<int>>::iterator j = c2.erase(i);
77        assert(*j == 3);
78    }
79#endif
80#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
81}
82