[C++-sig] Smart Pointers in Boost.Python withAutomaticDereferencing

English, Mark Mark.English at rbccm.com
Tue May 20 09:57:46 CEST 2008

-----Original Message-----
From: c++-sig-bounces at python.org [mailto:c++-sig-bounces at python.org] On
Behalf Of Ralf W. Grosse-Kunstleve
Sent: 20 May 2008 00:20
To: Development of Python/C++ integration
Subject: Re: [C++-sig] Smart Pointers in Boost.Python

> No, sorry.

> Very wild idea: can your smart pointer be converted both ways to/from
a boost::shared_ptr?
> And are all your smart pointer objects passed by value or const&?
> Then maybe a custom rvalue converter could do the trick.

> I hope someone else with actual experience in this area will be able
to help.

> Ralf

Have you tried using your own custom pointer as the held_type for the
class_ ?
i.e. class_<A, my_custom_ptr<A> >("A");

In many cases this works reasonably well as long as the suitable
typedefs and functions are in place in my_custom_ptr.

You will probably hit problems if you derive from your C++ types in
Python (Python inheritance/polymorphism), store my_custom_ptr pointers
to instances of these Python derived classes in your C++ code, and
expose these back to your Python code. For some people that is not a

----Apologies for this sig----

This email is intended only for the use of the individual(s) to whom
it is addressed and may be privileged and confidential.

Unauthorised use or disclosure is prohibited. If you receive this
e-mail in error, please advise immediately and delete the original
message without copying, using, or telling anyone about its contents.

This message may have been altered without your or our knowledge and
the sender does not accept any liability for any errors or omissions
in the message.

This message does not create or change any contract.  Royal Bank of
Canada and its subsidiaries accept no responsibility for damage caused
by any viruses contained in this email or its attachments.  Emails may
be monitored.

RBC Capital Markets is a business name used by branches and
subsidiaries of Royal Bank of Canada, including Royal Bank of Canada,
London branch and Royal Bank of Canada Europe Limited. In accordance
with English law requirements, details regarding Royal Bank of Canada
Europe Limited are set out below:

Registered in England and Wales 995939
Registered Address: 71 Queen Victoria Street, London, EC4V 4DE.
Authorised and regulated by the Financial Service Authority.
Member of the London Stock Exchange

More information about the Cplusplus-sig mailing list