From: <al...@ya...> - 2012-06-16 18:20:26
|
Hello, I am trying to use stl containers in my SWIG bindings. Everything works perfectly except for stl map handelling in Perl. On C++ side I have std::map<std::string, std::string> TryMap(const std::map<std::string, std::string> &map) { std::map<std::string, std::string> modified(map); modified["7"] = "!"; return modified; } SWIG config look like this %module stl %include "std_string.i" %include "std_map.i" %template(StringStringMap) std::map<std::string, std::string>; %{ #include "stl.h" %} %include "stl.h" In my Python script I can call TryMap this way >> print dict(stl.TryMap({'a': '4'})) and get beatiful output >> {'a': '4', '7': '!'} but in Perl I call >> print Dumper stl::TryMap({'a' => '4}); and get an error >> TypeError in method 'TryMap', argument 1 of type 'std::map< std::string,std::string > const &' at perl.pl line 7. I can actually do something like >> my $map = stl::TryMap(stl::StringStringMap->new()); >> print $map->get('7'); and get '!', but this is not an option because there is a lot of legacy code using "TryMap" that expects normal perl hash as its output. I belive there is a way work this out because SWIG solves this partucal problem nicely in Python and even in Perl if I use stl vectors and strings but not maps. Is there any way to handle stl map with Perl in SWIG? |