{"action":"opened","issue":{"url":"https://api.github.com/repos/wjakob/pybind11/issues/8","labels_url":"https://api.github.com/repos/wjakob/pybind11/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/wjakob/pybind11/issues/8/comments","events_url":"https://api.github.com/repos/wjakob/pybind11/issues/8/events","html_url":"https://github.com/wjakob/pybind11/issues/8","id":116653787,"number":8,"title":"PYBIND11_DECLARE_HOLDER_TYPE with std::shared_ptr","user":{"login":"Vayu","id":626781,"avatar_url":"https://avatars.githubusercontent.com/u/626781?v=3","gravatar_id":"","url":"https://api.github.com/users/Vayu","html_url":"https://github.com/Vayu","followers_url":"https://api.github.com/users/Vayu/followers","following_url":"https://api.github.com/users/Vayu/following{/other_user}","gists_url":"https://api.github.com/users/Vayu/gists{/gist_id}","starred_url":"https://api.github.com/users/Vayu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vayu/subscriptions","organizations_url":"https://api.github.com/users/Vayu/orgs","repos_url":"https://api.github.com/users/Vayu/repos","events_url":"https://api.github.com/users/Vayu/events{/privacy}","received_events_url":"https://api.github.com/users/Vayu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-12T22:18:47Z","updated_at":"2015-11-12T22:18:47Z","closed_at":null,"body":"The automatic transparent conversions do not seem to work for `std::shared_ptr`.\r\n\r\nI looked at the example8 and it seems that `ref<T>` class there differs from `shared_ptr` in one apparently crucial aspect, it has user-defined conversion\r\n```C++\r\noperator T* () { return m_ptr; }\r\n```\r\nwhich allows it to be passed as the first argument to `cast` function.\r\n\r\nI managed to get automatic conversion to work with `shared_ptr` by adding\r\n```C++\r\ndiff --git a/include/pybind11/cast.h b/include/pybind11/cast.h\r\nindex 5fe9342..1cb4ff4 100644\r\n--- a/include/pybind11/cast.h\r\n+++ b/include/pybind11/cast.h\r\n@@ -527,6 +527,12 @@ public:\r\n     explicit operator type&() { return *(this->value); }\r\n     explicit operator holder_type&() { return holder; }\r\n     explicit operator holder_type*() { return &holder; }\r\n+\r\n+    using type_caster<type>::cast;\r\n+    static PyObject *cast(const holder_type &src, return_value_policy policy, PyObject *parent) {\r\n+      return type_caster<type>::cast(src.get(), policy, parent);\r\n+    }\r\n+\r\n protected:\r\n     holder_type holder;\r\n };\r\n```\r\n\r\nBut perhaps there is a better way?"}}