[C++-sig] Converting a python dictionary rvalue to a T* in boost.python

David Abrahams dave at boost-consulting.com
Fri Jul 28 20:47:29 CEST 2006

Kevin Jones <investtcartier at yahoo.com> writes:

> Hi all,
> I have a c++ class T that implements an extended
> table. Additionally, I have a C++ function that takes
> a T* as an argument void (E.g. - f(T* t) ). How do I
> create converter to convert an 
> arbitrary python dictionary in boost.python to a T* as
> an argument?

There's no good way to do it.  Well, you could do this, if you want to
do it a "bad" way:

   1. define an rvalue from_python converter that converts an arbitrary
   dictionary to a T object.

   2. create a thin wrapper around f:

        void wrapf(T const& x) { f(&const_cast<T&>(x)); }
      and wrap that as f in PYthon.


Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list