[C++-sig] Re: returning auto_ptr, `No to_python converter' ?

Jacques A. Vidrine nectar-pycpp at celabo.org
Wed Jun 18 23:27:10 CEST 2003


On Wed, Jun 18, 2003 at 04:59:52PM -0400, David Abrahams wrote:
> And why does that confuse you?  That seems to show appropriate
> solutions to the question you posed.

excerpt from auto_ptr.cpp:

     45 std::auto_ptr<X> make()
     46 {
     47     return std::auto_ptr<X>(new X(77));
     48 }
   ...
     85     def("make", make);

That is in essence what I was attempting to accomplish.  I did not see
any other `scaffolding' to make this work.  A noteable difference is
that my `X' is non-copyable, but I didn't believe that was what was
tripping me up.

> Well, given that you're not actually dealing with std::string, the
> above advice is now wrong.

Oh, I realized that -- it was useful for the insight nonetheless.

Using register_ptr_to_python worked like a charm, but then I finally
noticed the piece I was missing.  Rather than,

     std::auto_ptr<T> make();
     //...
     class_<T, boost::noncopyable>("T", no_init)
        //...
        ;
     def("make", make);

I needed

     std::auto_ptr<T> make();
     //...
     class_<T, std::auto_ptr<T>, boost::noncopyable>("T", no_init)
        //     ^^^^^^^^^^^^^^^^
        //...          note new parameter
        ;
     def("make", make);

I believe this is the `HeldType' parameter that I was missing.  Now
the behavior is as I expected.  Boiling the issue down to a primitive
type or a specially-handled type before posting here obscured the
problem, I think.

Cheers,
-- 
Jacques Vidrine   . NTT/Verio SME      . FreeBSD UNIX       . Heimdal
nectar at celabo.org . jvidrine at verio.net . nectar at freebsd.org . nectar at kth.se




More information about the Cplusplus-sig mailing list