insert_iter_rvalue.pass.cpp revision f5256e16dfc425c1d466f6308d4026d529ce9e0b
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <vector>
11
12// iterator insert(const_iterator position, value_type&& x);
13
14#include <vector>
15#include <cassert>
16#include "../../../stack_allocator.h"
17#include "../../../MoveOnly.h"
18
19int main()
20{
21#ifdef _LIBCPP_MOVE
22    {
23        std::vector<MoveOnly> v(100);
24        std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
25        assert(v.size() == 101);
26        assert(i == v.begin() + 10);
27        int j;
28        for (j = 0; j < 10; ++j)
29            assert(v[j] == MoveOnly());
30        assert(v[j] == MoveOnly(3));
31        for (++j; j < 101; ++j)
32            assert(v[j] == MoveOnly());
33    }
34    {
35        std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
36        std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
37        assert(v.size() == 101);
38        assert(i == v.begin() + 10);
39        int j;
40        for (j = 0; j < 10; ++j)
41            assert(v[j] == MoveOnly());
42        assert(v[j] == MoveOnly(3));
43        for (++j; j < 101; ++j)
44            assert(v[j] == MoveOnly());
45    }
46#endif
47}
48