diff --git a/Examples/test-suite/cpp11_std_unique_ptr.i b/Examples/test-suite/cpp11_std_unique_ptr.i index 518d9be6e..9bd65b97f 100644 --- a/Examples/test-suite/cpp11_std_unique_ptr.i +++ b/Examples/test-suite/cpp11_std_unique_ptr.i @@ -1,6 +1,6 @@ %module cpp11_std_unique_ptr -#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) +#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY) || defined(SWIGPERL) %include "std_unique_ptr.i" diff --git a/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl b/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl new file mode 100644 index 000000000..ce64bbf00 --- /dev/null +++ b/Examples/test-suite/perl5/cpp11_std_unique_ptr_runme.pl @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::More tests => 6; +BEGIN { use_ok('cpp11_std_unique_ptr') } +require_ok('cpp11_std_unique_ptr'); + +my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first"); +my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second"); +is(cpp11_std_unique_ptr::Klass::getTotal_count, 2, "have 2 pointers"); + +undef $k1; +is(cpp11_std_unique_ptr::Klass::getTotal_count, 1, "left 1 pointer"); + +is($k2->getLabel, "second", "proper label"); + +undef $k2; +is(cpp11_std_unique_ptr::Klass::getTotal_count, 0, "remove all pointers"); diff --git a/Lib/perl5/std_unique_ptr.i b/Lib/perl5/std_unique_ptr.i new file mode 100644 index 000000000..163c7c2d1 --- /dev/null +++ b/Lib/perl5/std_unique_ptr.i @@ -0,0 +1,19 @@ +/* ----------------------------------------------------------------------------- + * std_unique_ptr.i + * + * The typemaps here allow handling functions returning std::unique_ptr<>, + * which is the most common use of this type. If you have functions taking it + * as parameter, these typemaps can't be used for them and you need to do + * something else (e.g. use shared_ptr<> which SWIG supports fully). + * ----------------------------------------------------------------------------- */ + +%define %unique_ptr(TYPE) +%typemap (out) std::unique_ptr< TYPE > %{ + %set_output(SWIG_NewPointerObj($1.release(), $descriptor(TYPE *), SWIG_POINTER_OWN | %newpointer_flags)); +%} +%template() std::unique_ptr< TYPE >; +%enddef + +namespace std { + template class unique_ptr {}; +}