File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#include < memory>
5
5
6
+ struct NonCopyable {
7
+ NonCopyable (int x) : x(x) {}
8
+ NonCopyable (const NonCopyable &) = delete ;
9
+ NonCopyable (NonCopyable &&other) : x(other.x) { other.x = -123 ; }
10
+
11
+ int method (int y) const { return x * y; }
12
+ int mutMethod (int y) {
13
+ x = y;
14
+ return y;
15
+ }
16
+
17
+ int x;
18
+ };
19
+
20
+ struct NonCopyableDerived : public NonCopyable {
21
+ NonCopyableDerived (int x) : NonCopyable(x) {}
22
+ };
23
+
24
+
25
+ inline std::shared_ptr<NonCopyable> getNonCopyableSharedPtr () { return std::make_shared<NonCopyableDerived>(42 ); }
26
+ inline std::unique_ptr<NonCopyable> getNonCopyableUniquePtr () { return std::make_unique<NonCopyableDerived>(42 ); }
27
+
6
28
std::unique_ptr<int > makeInt () {
7
29
return std::make_unique<int >(42 );
8
30
}
Original file line number Diff line number Diff line change @@ -41,5 +41,17 @@ StdUniquePtrTestSuite.test("custom dtor") {
41
41
expectEqual ( dtorCalled, true )
42
42
}
43
43
44
+ StdUniquePtrTestSuite . test ( " Test move only types behind smart pointers " ) {
45
+ let sp = getNonCopyableSharedPtr ( )
46
+ let up = getNonCopyableUniquePtr ( )
47
+ let f1 = sp. pointee. x
48
+ expectEqual ( f1, 42 )
49
+ expectEqual ( sp. pointee. method ( 1 ) , 42 )
50
+ let f2 = up. pointee. x
51
+ expectEqual ( f2, 42 )
52
+ expectEqual ( up. pointee. method ( 1 ) , 42 )
53
+ let _ = up. pointee. x
54
+ }
55
+
44
56
runAllTests ( )
45
57
You can’t perform that action at this time.
0 commit comments