Skip to content

Commit 8fbc44f

Browse files
committed
Add move rules for array, map, unique_ptr and vector
1 parent fd2ea09 commit 8fbc44f

11 files changed

Lines changed: 119 additions & 0 deletions

File tree

‎rules/array/src.cpp‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@ std::size_t f2(const std::array<T1, T2> &o) {
1919
template <typename T1, std::size_t T2> T1 *f3(std::array<T1, T2> &o) {
2020
return o.data();
2121
}
22+
23+
template <typename T1, std::size_t T2>
24+
std::array<T1, T2> f4(std::array<T1, T2> &&o) {
25+
return std::array<T1, T2>(std::move(o));
26+
}
27+
28+
template <typename T1, std::size_t T2>
29+
std::array<T1, T2> &f5(std::array<T1, T2> &dst, std::array<T1, T2> &&src) {
30+
return dst.operator=(std::move(src));
31+
}

‎rules/array/tgt_refcount.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ fn f1<T1>(a0: Ptr<T1>) -> Ptr<T1> {
1212
fn f3<T1>(a0: Ptr<T1>) -> Ptr<T1> {
1313
a0
1414
}
15+
16+
fn f5<T1: ByteRepr + Clone>(a0: Ptr<Vec<T1>>, a1: &mut Vec<T1>) {
17+
a0.write(std::mem::take(&mut *a1))
18+
}

‎rules/array/tgt_unsafe.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ unsafe fn f2<T1>(a0: Vec<T1>) -> usize {
1818
unsafe fn f3<T1>(a0: &mut Vec<T1>) -> *mut T1 {
1919
a0.as_mut_ptr()
2020
}
21+
22+
unsafe fn f4<T1>(a0: &mut Vec<T1>) -> Vec<T1> {
23+
std::mem::take(&mut *a0)
24+
}
25+
26+
unsafe fn f5<T1>(a0: &mut Vec<T1>, a1: &mut Vec<T1>) {
27+
*a0 = std::mem::take(&mut *a1)
28+
}

‎rules/map/src.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ template <typename T1, typename T2>
117117
T2 &f23(typename std::map<T1, T2>::iterator it) {
118118
return it->second;
119119
}
120+
121+
template <typename T1, typename T2> std::map<T1, T2> f24(std::map<T1, T2> &&o) {
122+
return std::map<T1, T2>(std::move(o));
123+
}
124+
125+
template <typename T1, typename T2>
126+
std::map<T1, T2> &f25(std::map<T1, T2> &dst, std::map<T1, T2> &&src) {
127+
return dst.operator=(std::move(src));
128+
}

‎rules/map/tgt_refcount.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,15 @@ fn f22<T1: Ord + Clone + 'static, T2: 'static>(a0: RefcountMapIter<T1, T2>) -> V
139139
fn f23<T1: Ord + Clone + 'static, T2: 'static>(a0: RefcountMapIter<T1, T2>) -> Value<T2> {
140140
a0.second()
141141
}
142+
143+
fn f24<T1: 'static, T2: 'static>(a0: Ptr<BTreeMap<T1, Value<T2>>>) -> BTreeMap<T1, Value<T2>> {
144+
a0.with_mut(|__v: &mut BTreeMap<T1, Value<T2>>| std::mem::take(__v))
145+
}
146+
147+
fn f25<T1: 'static, T2: 'static>(
148+
a0: Ptr<BTreeMap<T1, Value<T2>>>,
149+
a1: Ptr<BTreeMap<T1, Value<T2>>>,
150+
) {
151+
let __src = a1.with_mut(|__v: &mut BTreeMap<T1, Value<T2>>| std::mem::take(__v));
152+
a0.write(__src)
153+
}

‎rules/map/tgt_unsafe.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ unsafe fn f22<T1: Ord + Clone, T2>(a0: UnsafeMapIterator<T1, T2>) -> *const T1 {
102102
unsafe fn f23<T1: Ord + Clone, T2>(a0: UnsafeMapIterator<T1, T2>) -> *mut T2 {
103103
a0.second()
104104
}
105+
106+
unsafe fn f24<T1, T2>(a0: &mut BTreeMap<T1, Box<T2>>) -> BTreeMap<T1, Box<T2>> {
107+
std::mem::take(&mut *a0)
108+
}
109+
110+
unsafe fn f25<T1, T2>(a0: &mut BTreeMap<T1, Box<T2>>, a1: &mut BTreeMap<T1, Box<T2>>) {
111+
*a0 = std::mem::take(&mut *a1)
112+
}

‎rules/unique_ptr/src.cpp‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,22 @@ template <typename T1> std::unique_ptr<T1> f10() {
5555
template <typename T1> std::unique_ptr<T1[]> f11() {
5656
return std::unique_ptr<T1[]>();
5757
}
58+
59+
template <typename T1> std::unique_ptr<T1> f12(std::unique_ptr<T1> &&o) {
60+
return std::unique_ptr<T1>(std::move(o));
61+
}
62+
63+
template <typename T1> std::unique_ptr<T1[]> f13(std::unique_ptr<T1[]> &&o) {
64+
return std::unique_ptr<T1[]>(std::move(o));
65+
}
66+
67+
template <typename T1>
68+
std::unique_ptr<T1> &f14(std::unique_ptr<T1> &dst, std::unique_ptr<T1> &&src) {
69+
return dst.operator=(std::move(src));
70+
}
71+
72+
template <typename T1>
73+
std::unique_ptr<T1[]> &f15(std::unique_ptr<T1[]> &dst,
74+
std::unique_ptr<T1[]> &&src) {
75+
return dst.operator=(std::move(src));
76+
}

‎rules/unique_ptr/tgt_refcount.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,19 @@ fn f10<T1>() -> Option<Value<T1>> {
5959
fn f11<T1>() -> Option<Value<Box<[T1]>>> {
6060
None
6161
}
62+
63+
fn f12<T1>(a0: &mut Option<Value<T1>>) -> Option<Value<T1>> {
64+
a0.take()
65+
}
66+
67+
fn f13<T1>(a0: &mut Option<Value<Box<[T1]>>>) -> Option<Value<Box<[T1]>>> {
68+
a0.take()
69+
}
70+
71+
fn f14<T1: ByteRepr>(a0: Ptr<Option<Value<T1>>>, a1: &mut Option<Value<T1>>) {
72+
a0.write(a1.take())
73+
}
74+
75+
fn f15<T1: ByteRepr>(a0: Ptr<Option<Value<Box<[T1]>>>>, a1: &mut Option<Value<Box<[T1]>>>) {
76+
a0.write(a1.take())
77+
}

‎rules/unique_ptr/tgt_unsafe.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,19 @@ unsafe fn f10<T1: Default>() -> Option<Box<T1>> {
5353
unsafe fn f11<T1>() -> Option<Box<[T1]>> {
5454
None
5555
}
56+
57+
unsafe fn f12<T1>(a0: &mut Option<Box<T1>>) -> Option<Box<T1>> {
58+
a0.take()
59+
}
60+
61+
unsafe fn f13<T1>(a0: &mut Option<Box<[T1]>>) -> Option<Box<[T1]>> {
62+
a0.take()
63+
}
64+
65+
unsafe fn f14<T1>(a0: &mut Option<Box<T1>>, a1: &mut Option<Box<T1>>) {
66+
*a0 = a1.take()
67+
}
68+
69+
unsafe fn f15<T1>(a0: &mut Option<Box<[T1]>>, a1: &mut Option<Box<[T1]>>) {
70+
*a0 = a1.take()
71+
}

‎rules/vector/src.cpp‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,3 +527,12 @@ template <typename T1, typename T2 = std::allocator<T1>>
527527
void f106(std::vector<T1, T2> &o) {
528528
return o.shrink_to_fit();
529529
}
530+
531+
template <typename T1> std::vector<T1> f107(std::vector<T1> &&o) {
532+
return std::vector<T1>(std::move(o));
533+
}
534+
535+
template <typename T1, typename T2 = std::allocator<T1>>
536+
std::vector<T1, T2> f108(std::vector<T1, T2> &&o) {
537+
return std::vector<T1, T2>(std::move(o));
538+
}

0 commit comments

Comments
 (0)