Help with shared pointers and std::pair
Hugh Sorby <[email protected]>
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <[email protected]> |
Is anyone able to help with the following:
I have the following code:
test.h
#pragma once
#include <string>
#include <memory>
#include <utility>
class Test {
public:
std::pair<std::shared_ptr<std::string>, int> test(bool isNull) {
return isNull ? std::make_pair(nullptr, 0) : std::make_pair(std::make_shared<std::string>("test"), 3);
}
std::pair<std::string, int> another(bool isNull) {
return isNull ? std::make_pair("", 5) : std::make_pair("something", 8);
}
};
test.i
%module "test"
%include "std_shared_ptr.i"
%include "std_string.i"
%shared_ptr( std::string )
%template(Thingy) std::shared_ptr< std::string >;
%template(SmartPair) std::pair< std::shared_ptr< std::string >, int >;
%template(StringInt) std::pair< std::string, int >;
%include "test.h"
check.py
import test
t = test.Test()
print(t.test(True))
print(t.test(False))
print(t.another(True))
print(t.another(False))
The output of python check.py is:
(<test.Thingy; proxy of <Swig Object of type 'std::shared_ptr< std::string > *' at 0x11052eab0> >, 0)
(<test.Thingy; proxy of <Swig Object of type 'std::shared_ptr< std::string > *' at 0x11052eab0> >, 3)
('', 5)
('something', 8)
But what I would like to see is:
(None, 0)
(<test.Thingy; proxy of <Swig Object of type 'std::shared_ptr< std::string > *' at 0x11052eab0> >, 3)
('', 5)
('something', 8)
Is someone able to explain what is going on here please?
Many thanks.
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user