[C++-sig] Re: implicitly_convertible<> & auto_ptr
Nicolas Lelong
nico_ml at mgdesign.org
Tue Feb 18 17:48:58 CET 2003
> Can't you do it with a wrapper?
> addBigDataDerived(BigDataStore &store, char const* name,
std::auto_ptr<BigDataDerived> data){store.addBigData(name,data);}
> python::class_<BigDataStore, boost::noncopyable>("BigDataStore")
> .def("addBigData", &BigDataStore::addBigData,
python::with_custodian_and_ward<1,2>() )
> .def("addBigData", &addBigDataDerived,
python::with_custodian_and_ward<1,2>() );
Ooops, by the way, it should be "python::with_custodian_and_ward<1,3>()" but
I do wonder if it's really useful because of the auto_ptr stuff already
stating a transfer of ownership.
>
> I know it isn't very convenient, but it may work;
Yep, thanks, that's a valid workaround that will suit my needs for the
moment. I'm still curious about the implicitly_convertible<> stuff.
I have to train to get the 'wrapper reflex' !
> BTW how is this supposed to work:
> big = BigDataDerived()
> bigstore = BigDataStore()
> bigstore.addBigData('dumb', big)
> big.doSomething() ///// <- is it going to crash???
I'm not yet very confident with Python & BPL ownership rules, but it seems
that in the above the transfer of ownership is done, and 'big' is no longer
a 'valid reference' to the object transfered. I added a small 'doSomething'
method, and your test case leads to a friendly 'bad argument type for
built-in operation' which, I suppose, indicates the 'big' object is no
longer accessible via the 'big' symbol.
More information about the Cplusplus-sig
mailing list