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 33
44#include < memory>
55
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+
628std::unique_ptr<int > makeInt () {
729 return std::make_unique<int >(42 );
830}
Original file line number Diff line number Diff line change @@ -41,5 +41,17 @@ StdUniquePtrTestSuite.test("custom dtor") {
4141 expectEqual ( dtorCalled, true )
4242}
4343
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+
4456runAllTests ( )
4557
You can’t perform that action at this time.
0 commit comments