• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // iterator insert(const_iterator position, value_type&& x);
13 
14 #if _LIBCPP_DEBUG >= 1
15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16 #endif
17 
18 #include <vector>
19 #include <cassert>
20 #include "../../../stack_allocator.h"
21 #include "../../../MoveOnly.h"
22 #include "min_allocator.h"
23 
main()24 int main()
25 {
26 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
27     {
28         std::vector<MoveOnly> v(100);
29         std::vector<MoveOnly>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
30         assert(v.size() == 101);
31         assert(i == v.begin() + 10);
32         int j;
33         for (j = 0; j < 10; ++j)
34             assert(v[j] == MoveOnly());
35         assert(v[j] == MoveOnly(3));
36         for (++j; j < 101; ++j)
37             assert(v[j] == MoveOnly());
38     }
39     {
40         std::vector<MoveOnly, stack_allocator<MoveOnly, 300> > v(100);
41         std::vector<MoveOnly, stack_allocator<MoveOnly, 300> >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
42         assert(v.size() == 101);
43         assert(i == v.begin() + 10);
44         int j;
45         for (j = 0; j < 10; ++j)
46             assert(v[j] == MoveOnly());
47         assert(v[j] == MoveOnly(3));
48         for (++j; j < 101; ++j)
49             assert(v[j] == MoveOnly());
50     }
51 #if _LIBCPP_DEBUG >= 1
52     {
53         std::vector<int> v1(3);
54         std::vector<int> v2(3);
55         v1.insert(v2.begin(), 4);
56         assert(false);
57     }
58 #endif
59 #if __cplusplus >= 201103L
60     {
61         std::vector<MoveOnly, min_allocator<MoveOnly>> v(100);
62         std::vector<MoveOnly, min_allocator<MoveOnly>>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3));
63         assert(v.size() == 101);
64         assert(i == v.begin() + 10);
65         int j;
66         for (j = 0; j < 10; ++j)
67             assert(v[j] == MoveOnly());
68         assert(v[j] == MoveOnly(3));
69         for (++j; j < 101; ++j)
70             assert(v[j] == MoveOnly());
71     }
72 #if _LIBCPP_DEBUG >= 1
73     {
74         std::vector<int, min_allocator<int>> v1(3);
75         std::vector<int, min_allocator<int>> v2(3);
76         v1.insert(v2.begin(), 4);
77         assert(false);
78     }
79 #endif
80 #endif
81 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
82 }
83