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
36
Examples/test-suite/ruby/cpp11_move_typemaps_runme.rb
Normal file
36
Examples/test-suite/ruby/cpp11_move_typemaps_runme.rb
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'swig_assert'
|
||||
|
||||
require 'cpp11_move_typemaps'
|
||||
|
||||
Cpp11_move_typemaps::Counter.reset_counts()
|
||||
mo = Cpp11_move_typemaps::MoveOnly.new(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)
|
||||
mo = nil
|
||||
Cpp11_move_typemaps::Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
|
||||
Cpp11_move_typemaps::Counter.reset_counts()
|
||||
mo = Cpp11_move_typemaps::MovableCopyable.new(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)
|
||||
mo = nil
|
||||
Cpp11_move_typemaps::Counter.check_counts(1, 0, 0, 1, 0, 2)
|
||||
|
||||
mo = Cpp11_move_typemaps::MoveOnly.new(222)
|
||||
Cpp11_move_typemaps::MoveOnly.take(mo)
|
||||
exception_thrown = false
|
||||
begin
|
||||
Cpp11_move_typemaps::MoveOnly.take(mo)
|
||||
rescue RuntimeError => e
|
||||
if (!e.to_s.include? "cannot release ownership as memory is not owned")
|
||||
raise RuntimeError, "incorrect exception message: #{e.to_s}"
|
||||
end
|
||||
exception_thrown = true
|
||||
end
|
||||
if (!exception_thrown)
|
||||
raise RuntimeError, "Should have thrown 'Cannot release ownership as memory is not owned' error"
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue