[ruby] For swig::from, use template specialization to convert shared_ptr<const T> to shared_ptr<T>.
This commit is contained in:
parent
b8d383cb4a
commit
f96c2ad73d
5 changed files with 72 additions and 0 deletions
47
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
47
Examples/test-suite/cpp11_shared_ptr_const.i
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
%module cpp11_shared_ptr_const
|
||||
|
||||
%{
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
Foo(int i) : m(i) {}
|
||||
int get_m() { return m;}
|
||||
int m;
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec() {
|
||||
std::vector<std::shared_ptr<Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(7)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec() {
|
||||
std::vector<std::shared_ptr<const Foo> > result;
|
||||
result.push_back( std::shared_ptr<Foo>(new Foo(7)) );
|
||||
return result;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%include <std_shared_ptr.i>
|
||||
%include <std_vector.i>
|
||||
|
||||
%shared_ptr(Foo);
|
||||
|
||||
%template (FooVector) std::vector<std::shared_ptr<Foo> >;
|
||||
%template (FooConstVector) std::vector<std::shared_ptr<Foo const> >;
|
||||
|
||||
std::vector<std::shared_ptr<Foo> > foo_vec() const;
|
||||
std::vector<std::shared_ptr<const Foo> > const_foo_vec() const;
|
||||
|
||||
class Foo
|
||||
{
|
||||
public:
|
||||
Foo(int i);
|
||||
int get_m();
|
||||
int m;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue