Menu

#685 c++ std::map fails with class in python

closed-fixed
szager
python (260)
5
2011-04-25
2006-06-01
B Martin
No

Related to bug 1480074

In SWIG 1.3.21 it was possible to create a map from the
std::map class that mapped to a c++ class, and
subsequently modify the contents of the class from
Python. Using the latest CVS source (or any release
version since 1.3.21), it is possible to create and
manipulate the map and it's contents (the classes), but
not the member variables of the class.

Here are the contents of test_std_map.i:

%module SWIGTest

%inline %{
int i;
class TestA {
public:
TestA() { i = 1; }
int i;
};
%}
%include std_pair.i
%include std_map.i

namespace std
{
%template(pairii) pair<int,int>;
%template(mapii) map<int,int>;
%template(pairita) pair<int,TestA>;
%template(mapita) map<int,TestA>;
}
==========================================

And a sample script:
>>> from SWIGTest import *
>>> a = mapita()
>>> a[1] = TestA()
>>> a[1].i
1
>>> a[1].i = 2
>>> a[1].i
1

Discussion

  • William Fulton

    William Fulton - 2011-02-18

    Just a note that the behaviour is still the same in svn (just before swig-2.0.2 release)

     
  • szager

    szager - 2011-04-25

    Fixed in revision 12643.

     
  • szager

    szager - 2011-04-25
    • assigned_to: marcelomatus --> szager
    • status: open --> closed-fixed
     

Log in to post a comment.