[C++-sig] Mapping C++ typedefs to Python

Sylvain Pion Sylvain.Pion at sophia.inria.fr
Wed Nov 7 20:12:36 CET 2007

Stefan Seefeld a écrit :
> Nat Goodspeed wrote:
>> Sylvain Pion wrote:
>>> I use typedefs in C++, that is, several names for the same type
>>> (enums in my case).
>>> Is it possible to export this in Python?
>>> Is there the equivalent of typedefs in Python, and how
>>> can I specify this using Boost.Python?
>> enums:
>> http://boost.org/libs/python/doc/tutorial/doc/html/python/object.html#python.enums
>> If you have several C++ names for the same type, wouldn't it work to 
>> export each of them as though they were distinct? Unless I'm missing 
>> something, neither Python nor Boost.Python needs to know their sameness.
> That's technically correct, though I'm not sure what the purpose of this
> would be. Why duplicate code like this ? In Python type aliases are even
> easier than in C++, as types are assignable objects. So, why do it from
> within boost.python, and not inside python ?
> class Foo: pass
> Bar = Foo # 'Bar' is now the equivalent of C++'s typedef, aliasing 'Foo'

Thanks everybody for the suggestions and explanations.
I finally solved the problem within Python.

The reason I asked to do this within C++ using Boost.Python is that
this would have regrouped my code in the same place (after all, this
is a property of the C++ code which I want to describe).

BTW, this comes from me porting CGAL-Python to CGAL 3.3.

Sylvain Pion
INRIA Sophia-Antipolis
Geometrica Project-Team
CGAL, http://cgal.org/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 4309 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20071107/4f862e10/attachment.bin>

More information about the Cplusplus-sig mailing list