I have this simple C++ code:
class Contained {};
class CannotPickle {
public:
CannotPickle() {};
CannotPickle(std::vector<boost::shared_ptr<Contained>> new_vector)
: my_vector(new_vector) {};
std::vector<boost::shared_ptr<Contained>> my_vector;
};
struct CannotPickle_pickle_suite : boost::python::pickle_suite
{
static
boost::python::tuple
getinitargs(CannotPickle const& c)
{
return boost::python::make_tuple(c.my_vector);
}
};
I'm trying to enable pickling support for CannotPickle
like this:
class_<Contained>("Contained");
class_<std::vector<boost::shared_ptr<Contained>>>("ContainedPtrList")
.def(vector_indexing_suite<std::vector<boost::shared_ptr<Contained>>, true>());
class_<CannotPickle>("CannotPickle")
.def_pickle(CannotPickle_pickle_suite());
When I try to actually call pickle
on a CannotPickle
I get this error:
RuntimeError: Pickling of "MyModule.ContainedPtrList" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)
How can I enable pickling for a vector_indexing_suite
?