Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value. Based on SWIGTYPE && and std::unique_ptr typemaps which implement move semantics. Added for all languages, but untested for: Go, Ocaml, R, Scilab (and unlikely to be fully functional for same reasons as for std::unique_ptr support). Issue #999
This commit is contained in:
parent
de65875955
commit
dad7c93ca0
41 changed files with 909 additions and 19 deletions
42
Examples/test-suite/d/cpp11_move_typemaps_runme.1.d
Normal file
42
Examples/test-suite/d/cpp11_move_typemaps_runme.1.d
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module cpp11_move_typemaps_runme;
|
||||
|
||||
import cpp11_move_typemaps.Counter;
|
||||
import cpp11_move_typemaps.MoveOnly;
|
||||
import cpp11_move_typemaps.MovableCopyable;
|
||||
import std.conv;
|
||||
import std.algorithm;
|
||||
|
||||
void main() {
|
||||
{
|
||||
Counter.reset_counts();
|
||||
scope MoveOnly mo = new MoveOnly(111);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MoveOnly.take(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
{
|
||||
Counter.reset_counts();
|
||||
scope MovableCopyable mo = new MovableCopyable(111);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MovableCopyable.take(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
{
|
||||
scope MoveOnly mo = new MoveOnly(222);
|
||||
MoveOnly.take(mo);
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
MoveOnly.take(mo);
|
||||
} catch (Exception e) {
|
||||
if (!canFind(e.msg, "Cannot release ownership as memory is not owned"))
|
||||
throw new Exception("incorrect exception message: " ~ e.msg);
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new Exception("double usage of take should have been an error");
|
||||
}
|
||||
}
|
||||
42
Examples/test-suite/d/cpp11_move_typemaps_runme.2.d
Normal file
42
Examples/test-suite/d/cpp11_move_typemaps_runme.2.d
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
module cpp11_move_typemaps_runme;
|
||||
|
||||
import cpp11_move_typemaps.Counter;
|
||||
import cpp11_move_typemaps.MoveOnly;
|
||||
import cpp11_move_typemaps.MovableCopyable;
|
||||
import std.conv;
|
||||
import std.algorithm;
|
||||
|
||||
void main() {
|
||||
{
|
||||
Counter.reset_counts();
|
||||
scope MoveOnly mo = new MoveOnly(111);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MoveOnly.take(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
{
|
||||
Counter.reset_counts();
|
||||
scope MovableCopyable mo = new MovableCopyable(111);
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
MovableCopyable.take(mo);
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
}
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
{
|
||||
scope MoveOnly mo = new MoveOnly(222);
|
||||
MoveOnly.take(mo);
|
||||
bool exception_thrown = false;
|
||||
try {
|
||||
MoveOnly.take(mo);
|
||||
} catch (Exception e) {
|
||||
if (!canFind(e.msg, "Cannot release ownership as memory is not owned"))
|
||||
throw new Exception("incorrect exception message: " ~ e.msg);
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new Exception("double usage of take should have been an error");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue