Boost logo

Boost :

Subject: Re: [boost] Enums: naming question?
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2011-03-18 20:55:44


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
>>
>> In addition I have defined some functions that make the conversions from
>> these types
>>
>> template
>> native_type::type native_value(ScopedEnum e);
>>
>> template
>> underlying_type::type underlying_value(ScopedEnum e);
>>
>> I have defined all these under the boost::enums namespace.
>>
>> Do you have a better proposal for these (meta-)functions?
>>
>> 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
>>
>> Best,
>> Vicente
>>
>> P.S. Note native-type and native_value are yet in the doc as enum_type
>> and
>> enum_value.
>> The tutorial is really in a very draft state :(
>>
>>
> Perhaps you can summarize what these types and (meta-)functions are
> suppose
> to be/do? I trolled through the documentation but...it's kind of long for
> me to go through the whole thing at the moment :/
>
>

Yes of course.

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

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

Let me know if you need more details.

Best,
Vicente

--
View this message in context: http://boost.2283326.n4.nabble.com/Enums-naming-question-tp3388473p3388818.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