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
30
Examples/test-suite/javascript/cpp11_move_typemaps_runme.js
Normal file
30
Examples/test-suite/javascript/cpp11_move_typemaps_runme.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
var cpp11_move_typemaps = require("cpp11_move_typemaps");
|
||||
|
||||
cpp11_move_typemaps.Counter.reset_counts();
|
||||
mo = new cpp11_move_typemaps.MoveOnly(111);
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
cpp11_move_typemaps.MoveOnly.take(mo);
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
delete mo;
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
cpp11_move_typemaps.Counter.reset_counts();
|
||||
mo = new cpp11_move_typemaps.MovableCopyable(111);
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 0, 0, 0);
|
||||
cpp11_move_typemaps.MovableCopyable.take(mo);
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
delete mo;
|
||||
cpp11_move_typemaps.Counter.check_counts(1, 0, 0, 1, 0, 2);
|
||||
|
||||
mo = new cpp11_move_typemaps.MoveOnly(222);
|
||||
cpp11_move_typemaps.MoveOnly.take(mo);
|
||||
exception_thrown = false;
|
||||
try {
|
||||
cpp11_move_typemaps.MoveOnly.take(mo);
|
||||
} catch (e) {
|
||||
if (!e.message.includes("cannot release ownership as memory is not owned"))
|
||||
throw new Error("incorrect exception message:" + e.message);
|
||||
exception_thrown = true;
|
||||
}
|
||||
if (!exception_thrown)
|
||||
throw new Error("double usage of take should have been an error");
|
||||
Loading…
Add table
Add a link
Reference in a new issue