[C++-sig] enums and structs

David Abrahams david.abrahams at rcn.com
Mon May 20 00:50:34 CEST 2002


----- Original Message -----
From: "Achim Domma" <achim.domma at syynx.de>


> > -----Original Message-----
> > From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> > Behalf Of David Abrahams

> > No. It's the library which must do the conversion. When it's trying to
> > match an argument of my_enum_type, it looks for conversions which can
> > produce int, because it knows int is convertible to my_enum_type.
That's
> > why you should write it the way I did.
>
> Using your code, I tried the following:
>
<snip>

> Registering the conversion at position 1 causes an internal compiler
error
> (with /Zm1600):

I don't know what to say about that other than "there's a compiler bug".

> At position 2 I get the following error:
>
> E:\cvsroot\boost\boost/python/converter/implicit.hpp(41) : error C2440:
'='
> : cannot convert from 'int' to 'MagickLib::AlignType'
>         Conversion to enumeration type requires an explicit cast
> (static_cast, C-style cast or function-style cast)

This one's my fault; I forgot the rules for converting ints to enums.

Supporting this usage will require a Boost.Python library extension.
Probably the easiest thing to do is to give implicitly_convertible an
optional argument which allows an explicit conversion (in this case a
static_cast<>) to be specified.

Since Joel is doing some work with enums now, it might make sense for him
to implement this. What do you think, Joel?

> PS.: I really appreciate your tireless support, and try not to waste your
> time with stupid questions, but the inner working of boost.python is too
> much for my C++ skills.

No problem at all. However, I'm curious as to whether you're using is
understandable to you, at least in part. Did you read the documentation I
referenced? I ask because Boost.Python is a framework and I really want to
make it understandable and accessible. If you don't understand it yet, I at
least hope to make it learnable.

-Dave







More information about the Cplusplus-sig mailing list