#pragma once #include template void shared_ptr_implicitly_convertible() { boost::python::implicitly_convertible, std::shared_ptr>(); } template void register_shared_ptr() { boost::python::register_ptr_to_python>(); boost::python::register_ptr_to_python>(); } namespace dtl{ // primary class template template struct ImplConversionSharedPtr { void c() { shared_ptr_implicitly_convertible(); } }; // specialized class template template struct ImplConversionSharedPtr::value>::type> { void c() { } }; template struct bases_holder { typedef boost::python::bases Type; }; template<> struct bases_holder { typedef boost::python::bases<> Type; }; } template boost::python::class_, typename dtl::bases_holder::Type, NC> defineClass(char const* name, char const* docstring, typename std::enable_if_t::value>::type* = 0) { auto inst = boost::python::class_, typename dtl::bases_holder::Type, NC>(name, docstring); register_shared_ptr(); dtl::ImplConversionSharedPtr().c(); return inst; }; template boost::python::class_, typename dtl::bases_holder::Type, NC> defineClass(char const* name, char const* docstring) { auto inst = boost::python::class_, typename dtl::bases_holder::Type, NC>(name, docstring, boost::python::no_init); register_shared_ptr(); dtl::ImplConversionSharedPtr().c(); return inst; };