Re: enum_<T>::value

"Alexander Nasonov" <[email protected]>
Newsgroups gmane.comp.lib.boost.langbinding
Message-ID <[email protected]>
>Alexander Nasonov writes:
>> Dave Abrahams writes:
>>> Because on the Python side, enums are derived from int, which is
>>> represented as a signed long.
>>
>> I see.
>> It's still unclear what kind of warning a user should get in this
>> case? Python exception or C++ compile-time error? 
>
>Technically we should be smarter about it and use a Python long for
>representation when necessary.  Is compile-time detection even
>possible?

It's possible to detect at compile-time that some enum values are out of range.

    static_assert( !is_same<unsigned long, promote<SomeEnum>::type>::value );
    // promote<T> is in a queue for fast track review

If the goal is not to allow such enums at all (even if a user doesn't register big values), then it's fine, otherwise, compile-time detection is useless.
Though, I prefer automatic switch to other Python type when some enum values are out of [LONG_MIN, LONG_MAX] range.
There are several approaches to mapping C++ enum to Python type:
1. Find smallest Python integer type that can represent any given enum value (value-based mapping)
2. Find smallest Python integer type that can represent all _registered_ enum values.
3. Find smallest Python integer type that can represent all enum values even unregistered (I'm not sure that it's possible).
4. Find smallest Python integer type that can represent all values from a range allowed by C++ (0 - 2^n-1 if all enum values are positive).
5. Find smallest Python integer type that can represent all values of promoted C++ type.
6. Promote C++ enum and map resulting integral type to Python type.

4, 5 or 6 should be named "type-based mapping". 5 and 6 are probably the same in Python in many other languages but in theory they might give different results in some type model.
Personally, I prefer 6.

There might be other approaches in Langbinding depending on enum support in scripting language.

>> How Langbinding should handle it? These are interesting
>> questions. Different scripting languages have different set of
>> integer types. Some of them are equal to one of C++ int types, some
>> others have fixed size ints (like in Java on CORBAScript, where they
>> look very much like C++ ones but are different).  I thinks we need a
>> model of a scripting language.
>
>That's what the langbinding project is all about.
>
>> I go home now. Please, click on reply all when replying. Then, I'll be
>> able to reply from home. Or may be we should switch to
>> booost-langbinding mailing list?
>
>It couldn't hurt.

Once I was close to starting a topic about the model on wiki. I should definetely find time in a future.

--
Alexander Nasonov


-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc.  Get Certified Today
Register for a JBoss Training Course.  Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.