Hi, bp::object static_instance() { static bp::object* result = new bp::object(boost::ref(A::static_a)); return *result; }
Instead of exposing a function static_instance in your module, you can alternatively add a variable to your module's scope: scope sc; sc.attr("static_a") = boost::ref(A::static_a); //no copy here regards 2013/1/16 Michael Wild <them...@users.sourceforge.net>: > Dear all > > I struggle to find a way in which I can wrap a static instance in a > bp::object without copying it. The goal is to have object identity for > this static instance: > > struct A { > /*...*/ > static A static_a; > }; > > a A::a; > > bp::object static_instance() > { > static bp::object* result = new bp::object(A::static_a); // [1] > return *result; > } > > Wrapping A and static_instance with Boost.Python is no problem, and > everything works as expected, however the A::static_a that is being > passed to bp::object() at [1] is being copied, which defeats the whole > purpose. > > Anybody has an idea how achieve this? Thanks! > > Cheers > > Michael > _______________________________________________ > Cplusplus-sig mailing list > Cplusplus-sig@python.org > http://mail.python.org/mailman/listinfo/cplusplus-sig _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig