I'm currently working on creating a python wrapper for XCF using Boost.Python. During that project i stumbled upon the problem that i was wrapping some classes that used a custom smart pointer (i.e. not one from the boost library). Boost.Python is quite good at wrapping classes using smart pointers, but it has to know some things about the smart pointer used first.

Most importantly, it has to know how to get the "raw" pointer from the smart pointer and how to determine the type of the object that is being pointed to (given the type of the smart pointer). Finding documentation about telling Boost.Python how to work with an unknown type of smart pointer wasn't easy (which is why i am blogging this), but fortunately at some point i stumbled upon this. It's from the documentation of the Py++-package, but you don't have to be using Py++ to use the technique described in there.

You have to keep a lot of things in mind when implementing this (especially when the class your smart pointer is pointing to might also have some derived subclasses, in which case you should really take a look at the original example), but in essence it all boils down to this*. In that case, IceUtil::Handle<T> is the smart pointer i am working with. This class is coming from Ice, so if you're also using that, you might try creating something similar.

*Update 2017: That link is dead and I can't find any version of the old XCF source code anywhere. This should serve as a reminder to myself to always include all code examples directly in future blog posts and not link to some external resource which might go down after a while.