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
29
Examples/test-suite/python/cpp11_move_typemaps_runme.py
Normal file
29
Examples/test-suite/python/cpp11_move_typemaps_runme.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from cpp11_move_typemaps import *
|
||||
|
||||
Counter.reset_counts()
|
||||
mo = MoveOnly(111)
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0)
|
||||
MoveOnly.take(mo)
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
del mo
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
|
||||
Counter.reset_counts()
|
||||
mo = MovableCopyable(111)
|
||||
Counter.check_counts(1, 0, 0, 0, 0, 0)
|
||||
MovableCopyable.take(mo)
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
del mo
|
||||
Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
|
||||
mo = MoveOnly(222)
|
||||
MoveOnly.take(mo)
|
||||
exception_thrown = False
|
||||
try:
|
||||
MoveOnly.take(mo)
|
||||
except RuntimeError as e:
|
||||
if "cannot release ownership as memory is not owned" not in str(e):
|
||||
raise RuntimeError("incorrect exception message:" + str(e))
|
||||
exception_thrown = True
|
||||
if not exception_thrown:
|
||||
raise RuntimeError("Should have thrown 'Cannot release ownership as memory is not owned' error")
|
||||
Loading…
Add table
Add a link
Reference in a new issue