Boost logo

Boost :

Subject: Re: [boost] Enums: naming question?
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2011-03-19 04:10:35


Jeffrey Lee Hellrung, Jr.-2 wrote:
>
> On Fri, Mar 18, 2011 at 5:55 PM, Vicente Botet
> <vicente.botet_at_[hidden]>wrote:
>
>>
>> Jeffrey Lee Hellrung, Jr.-2 wrote:
>> >
>> > On Fri, Mar 18, 2011 at 2:10 PM, Vicente Botet
>> > <vicente.botet_at_[hidden]>wrote:
>> >
>> >> Hi,
>> >>
>> >> I'm developing a scoped enum library that use an emulation wrapping
>> the
>> >> native enum on a class to get scoped enumerators.
>> >>
>> >> I need some traits, to get the native type from the emulation, and the
>> >> coping class from the native one.
>> >> In addition there is an underlying type that is used to store the
>> >> enumerators. Next follows the names I have use in the library:
>> >>
>> >> native_type::type
>> >> underlying_type::type
>> >> scoping_type::type
>>
> [...]
>
>> >> If you need more details you can take a look in the sandbow/enums
>> >> directory
>> >>
>> http://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html
>>
> [...]
>
>> > Perhaps you can summarize what these types and (meta-)functions are
>> > suppose
>>
> [...]
>
>> When scoped enum classes are available we can use
>>
>> enum class EnumClass : short {E1, ... En};
>>
>> In this case the scoped enum class is already an enum.
>>
>> is_enum::value is true
>> typedef EnumClass EnumClassNative;
>> native_type::type is EnumClass
>> underlying_type::type is short
>> scoping_type::type is EnumClass
>

I don't know why the template parameter of the trait disappears each time.
Is the second time I have problems with < and >.

What I wanted to say was

is_enum::type is true
typedef EnumClass EnumClassNative;
native_type::type is EnumClass
underlying_type::type is short
scoping_type::type is EnumClass

>> When scoped enum classes is not supported the emulation uses the well
>> known
>> schema
>>
>> template
>> class EnumClass
>> {
>> public:
>> //! c++98 enum type
>> typedef enum {E1, ... En} type;
>> //! underlying type
>> typedef short underlying_type;
>> private:
>> underlying_type val_;
>> ...
>> };
>>
>> and of course EnumClass is not an enum :(
>>
>> is_enum::value is false
>> typedef EnumClass::type EnumClassNative;
>> native_type::type is EnumClassNative
>> underlying_type::type is short
>> scoping_type::type is EnumClass
>

And

is_enum::type is false
typedef EnumClass::type EnumClassNative;
native_type::type is EnumClassNative
underlying_type::type is short
scoping_type::type is EnumClass

>> Let me know if you need more details.
>>
>>
> Thanks, that helps, I think:
>
> So native_type is an enum type; why did you change the name from
> enum_type?
> Maybe native_enum_type would be better?
>

What I wanted to say by native was the enum type supported by the compiler.
Maybe be native_enum_type or simply enum_type are clearer, yes. What others
thing?

> I get underlying_type. Consider underlying_integral_type, to distinguish
> it
> from the "underlying enum" type...although it's longer :/ It just seems
> that native_type and underlying type almost sound like the same thing, and
> I
> could imagine easily getting confused.
>

I understand you and other can be confused. This was the reason of the post,
try to avoid the possible confusions ;-)

On C++0x there is already the trait underlying_type that is associated to
the storage. The same trait is used on the Opaque.Strong Types proposal. So
i will prefer to maintain underlying_type us such. The names I'm not happy
with are scoping and native.

> So what's with scoping_type? In one case, it's the scoped enum, and in
> the other case, it's the emulated scoped enum, but in both it looks like
> an
> identity operation. I don't get the point.
>

It is not the identity when the scoped enum is emulated. In any case is the
type giving scope to the enumerators, this was the reason for the name.

In the emulation scoping of the nested enum is the identity. With scoped
enums scoping and enum_type/native_type are identities.

I'm conscientious that this alternative emulation of enums has a major
drawback: the emulating type is not an enum and I can understand why others
have abandoned the idea. I just wanted to explore it in depth to see if the
whole design had more advantages than liabilities, but I suspect that I've
not reached it yet. As the emulation is not an enum we need some traits to
get the enum type and vice versa. The same is applicable for the value
conversion of these type.

Thanks a lot,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/Enums-naming-question-tp3388473p3389239.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk