{"action":"created","issue":{"url":"https://api.github.com/repos/swig/swig/issues/1226","repository_url":"https://api.github.com/repos/swig/swig","labels_url":"https://api.github.com/repos/swig/swig/issues/1226/labels{/name}","comments_url":"https://api.github.com/repos/swig/swig/issues/1226/comments","events_url":"https://api.github.com/repos/swig/swig/issues/1226/events","html_url":"https://github.com/swig/swig/issues/1226","id":312977260,"number":1226,"title":"NotImplementedError when using std::map with enum as key","user":{"login":"rwslord","id":8781867,"avatar_url":"https://avatars3.githubusercontent.com/u/8781867?v=4","gravatar_id":"","url":"https://api.github.com/users/rwslord","html_url":"https://github.com/rwslord","followers_url":"https://api.github.com/users/rwslord/followers","following_url":"https://api.github.com/users/rwslord/following{/other_user}","gists_url":"https://api.github.com/users/rwslord/gists{/gist_id}","starred_url":"https://api.github.com/users/rwslord/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rwslord/subscriptions","organizations_url":"https://api.github.com/users/rwslord/orgs","repos_url":"https://api.github.com/users/rwslord/repos","events_url":"https://api.github.com/users/rwslord/events{/privacy}","received_events_url":"https://api.github.com/users/rwslord/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-04-10T15:33:33Z","updated_at":"2018-04-22T01:29:34Z","closed_at":null,"author_association":"NONE","body":"I have the following code in C++:\r\n\r\n```cpp\r\n\r\nnamespace mscl\r\n{\r\n\r\nclass ChannelMask\r\n{\r\npublic:\r\n    ChannelMask();  //default constructor\r\n};\r\n\r\nclass WirelessTypes\r\n{\r\npublic:\r\n    enum DerivedChannelType\r\n    {\r\n        derived_rms = 0,\r\n        derived_peakToPeak = 1,\r\n    };\r\n\r\n    typedef std::map<DerivedChannelType, ChannelMask> DerivedChannelMasks;\r\n};\r\n\r\n}\r\n```\r\n\r\nMy swig .i file looks like this:\r\n\r\n```\r\n%include \"stdint.i\"\r\n%include \"std_string.i\"\r\n%include \"std_vector.i\"\r\n%include \"std_map.i\"\r\n%include \"std_shared_ptr.i\"\r\n\r\n%module mscl\r\n%{\r\n#include \"../WirelessTypes.h\"\r\n%}\r\n\r\n%include \"../WirelessTypes.h\"\r\n\r\nnamespace std\r\n{\r\n    %template(DerivedChannelMasks) map<mscl::WirelessTypes::DerivedChannelType, mscl::ChannelMask>;\r\n};\r\n```\r\n\r\nSWIG compiles this without errors. \r\n\r\nIf I run the following Python code when it was compiled with SWIG 3.0.6, it works fine. However, if I run the same code when it was compiled with **SWIG 3.0.12**, it gives the error shown below:\r\n\r\n```python\r\nmasks = mscl.DerivedChannelMasks()\r\nmasks[mscl.WirelessTypes.derived_rms] = mscl.ChannelMask()\r\n```\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"mscl.py\", line 7696, in __setitem__\r\n    return _mscl.DerivedChannelMasks___setitem__(self, *args)\r\nNotImplementedError: Wrong number or type of arguments for overloaded function 'DerivedChannelMasks___setitem__'.\r\n  Possible C/C++ prototypes are:\r\n    std::map< mscl::WirelessTypes::DerivedChannelType,mscl::ChannelMask >::__setitem__(std::map< enum mscl::WirelessTypes::DerivedChannelType,mscl::ChannelMask >::key_type const &)\r\n    std::map< mscl::WirelessTypes::DerivedChannelType,mscl::ChannelMask >::__setitem__(std::map< enum mscl::WirelessTypes::DerivedChannelType,mscl::ChannelMask >::key_type const &,std::map< enum mscl::WirelessTypes::DerivedChannelType,mscl::ChannelMask >::mapped_type const &)\r\n```\r\n\r\nMy apologies for the long example. This is part of a large project, and I tried narrowing it down as much as possible.\r\n\r\nIssue with **SWIG 3.0.12** when running the following command:\r\n```swig -c++ -python -modern -outdir <PATH_TO_OUTDIR> -o \"..\\MSCL_Wrap.cpp\" \"..\\MSCL_Interface.i\"```\r\n\r\nPython 2.7.11"},"comment":{"url":"https://api.github.com/repos/swig/swig/issues/comments/383347469","html_url":"https://github.com/swig/swig/issues/1226#issuecomment-383347469","issue_url":"https://api.github.com/repos/swig/swig/issues/1226","id":383347469,"user":{"login":"ojwb","id":164061,"avatar_url":"https://avatars0.githubusercontent.com/u/164061?v=4","gravatar_id":"","url":"https://api.github.com/users/ojwb","html_url":"https://github.com/ojwb","followers_url":"https://api.github.com/users/ojwb/followers","following_url":"https://api.github.com/users/ojwb/following{/other_user}","gists_url":"https://api.github.com/users/ojwb/gists{/gist_id}","starred_url":"https://api.github.com/users/ojwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ojwb/subscriptions","organizations_url":"https://api.github.com/users/ojwb/orgs","repos_url":"https://api.github.com/users/ojwb/repos","events_url":"https://api.github.com/users/ojwb/events{/privacy}","received_events_url":"https://api.github.com/users/ojwb/received_events","type":"User","site_admin":false},"created_at":"2018-04-22T01:29:34Z","updated_at":"2018-04-22T01:29:34Z","author_association":"MEMBER","body":"Here's a smaller and self-contained test-case, assuming that `ChannelMask`'s constructor isn't interesting:\r\n\r\n```\r\n%module mscl\r\n\r\n%include \"std_map.i\"\r\n\r\n%inline %{\r\n\r\nenum DerivedChannelType\r\n{\r\n    derived_rms = 0,\r\n    derived_peakToPeak = 1,\r\n};\r\n\r\n%}\r\n\r\n%template(DerivedChannelMasks) std::map<DerivedChannelType, int>;\r\n```\r\n\r\nTo run:\r\n\r\n```\r\nswig -c++ -python -modern  mscl.i && g++ -o _mscl.so -shared -fPIC `python-config --cflags` mscl_wrap.cxx && PYTHONPATH=. python -c 'import mscl; masks = mscl.DerivedChannelMasks(); masks[mscl.derived_rms] = 1'\r\n```\r\n\r\nUsing `git bisect` with that shows that this stopped working in 91aba9f719273778fe0196f9bc8659131c9e2cf8 - @wsfulton: any ideas?"}}
{"actor":{"display_login":"ojwb"}}