{"action":"created","issue":{"url":"https://api.github.com/repos/TRIQS/triqs/issues/264","labels_url":"https://api.github.com/repos/TRIQS/triqs/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/TRIQS/triqs/issues/264/comments","events_url":"https://api.github.com/repos/TRIQS/triqs/issues/264/events","html_url":"https://github.com/TRIQS/triqs/issues/264","id":111962650,"number":264,"title":"[c++2py] std::pair and std::tuple should be converted to tuple()","user":{"login":"krivenko","id":1328321,"avatar_url":"https://avatars.githubusercontent.com/u/1328321?v=3","gravatar_id":"","url":"https://api.github.com/users/krivenko","html_url":"https://github.com/krivenko","followers_url":"https://api.github.com/users/krivenko/followers","following_url":"https://api.github.com/users/krivenko/following{/other_user}","gists_url":"https://api.github.com/users/krivenko/gists{/gist_id}","starred_url":"https://api.github.com/users/krivenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krivenko/subscriptions","organizations_url":"https://api.github.com/users/krivenko/orgs","repos_url":"https://api.github.com/users/krivenko/repos","events_url":"https://api.github.com/users/krivenko/events{/privacy}","received_events_url":"https://api.github.com/users/krivenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-17T13:09:42Z","updated_at":"2015-10-17T13:25:10Z","closed_at":null,"body":"Hello,\r\n\r\nPresently c2py converters for `std::pair` and `std::tuple` return Python list objects. This may have undesirable side effects in the contexts where Python makes difference between mutable and immutable types. I have found that it is impossible to convert an `std::map` to Python dictionary using `std::pair` or `std::tuple` as map keys.\r\n```python\r\nfrom wrap_generator import *\r\n\r\nmodule = module_(full_name = \"pytriqs.issue264\", doc = \"Issue #264\")\r\n\r\nmodule.add_preamble(\"\"\"\r\n#include <utility>\r\n#include <tuple>\r\n#include <map>\r\n\r\nusing pair_to_double_t = std::map<std::pair<int,int>,double>;\r\nusing tuple_to_double_t = std::map<std::tuple<int,int>,double>;\r\n\r\npair_to_double_t make_ptd() {\r\n return {{std::make_pair(1,2),0.5}};\r\n}\r\n\r\ntuple_to_double_t make_ttd() {\r\n return {{std::make_tuple(1,2),0.5}};\r\n}\r\n\"\"\")\r\nmodule.add_include(\"<triqs/python_tools/converters/pair.hpp>\")\r\nmodule.add_include(\"<triqs/python_tools/converters/tuple.hpp>\")\r\nmodule.add_include(\"<triqs/python_tools/converters/map.hpp>\")\r\n\r\nmodule.add_function(\"pair_to_double_t make_ptd()\")\r\nmodule.add_function(\"tuple_to_double_t make_ttd()\")\r\n\r\nmodule.generate_code()\r\n```\r\nThis module compiles well, but when I try to use `make_ptd()` or `make_ttd()` I get an error:\r\n```\r\n>>> from issue264 import *\r\n>>> make_ptd()\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: unhashable type: 'list'\r\n>>> make_ttd()\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\nTypeError: unhashable type: 'list'\r\n```\r\nIt seems easy to fix this issue, just return `tuple()` instead of `list()` from the converters. But this would be a potential API break, so I want to know your opinion."},"comment":{"url":"https://api.github.com/repos/TRIQS/triqs/issues/comments/148915993","html_url":"https://github.com/TRIQS/triqs/issues/264#issuecomment-148915993","issue_url":"https://api.github.com/repos/TRIQS/triqs/issues/264","id":148915993,"user":{"login":"parcollet","id":1014945,"avatar_url":"https://avatars.githubusercontent.com/u/1014945?v=3","gravatar_id":"","url":"https://api.github.com/users/parcollet","html_url":"https://github.com/parcollet","followers_url":"https://api.github.com/users/parcollet/followers","following_url":"https://api.github.com/users/parcollet/following{/other_user}","gists_url":"https://api.github.com/users/parcollet/gists{/gist_id}","starred_url":"https://api.github.com/users/parcollet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/parcollet/subscriptions","organizations_url":"https://api.github.com/users/parcollet/orgs","repos_url":"https://api.github.com/users/parcollet/repos","events_url":"https://api.github.com/users/parcollet/events{/privacy}","received_events_url":"https://api.github.com/users/parcollet/received_events","type":"User","site_admin":false},"created_at":"2015-10-17T13:25:10Z","updated_at":"2015-10-17T13:25:10Z","body":"I have met exactly the same point a few days ago.\r\n@tayral : can you remind me your example, where we concluded we needed to convert into a tuple instead of a list ?\r\nAPI break: a priori yes, but how often do we use this ? What is the impact of such break ?"}}