Author Topic: strong enum support  (Read 9144 times)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
strong enum support
« on: October 25, 2010, 11:02:59 am »
Could our CC gurus have a quick look on the effort needed to support strong enums types (feature from C++0x).

Here's a little code snippet :

Code
enum class StrongEnum1
{
    on,
    off
};

enum class StrongEnum2
{
    on,
    off
};

int main()
{
    StrongEnum1 value1;
    value1 = StrongEnum1::on;

    return 0;
}

Current situation.

While typing the line "value1 = StrongEnum1::on;" :
- StrongEnum1 does not give a completion suggestion, due to this it has to be typed completely manually
- StrongEnum1:: does not provide a suggestion list of the possible enum values.

What do you guys think ?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: strong enum support
« Reply #1 on: October 25, 2010, 01:08:15 pm »
supported in rev6759. :)

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: strong enum support
« Reply #2 on: October 25, 2010, 08:10:21 pm »
it works perfectly :-)

Super great.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: strong enum support
« Reply #3 on: December 19, 2010, 09:52:26 am »
just found one little hickup.

When I tooltip over the enum class type, the tooltip shows 2 things :

enum Foo {}
class Foo {}


where it should only show :

enum class Foo {}

Note from time to time, it only says enum Foo. A bit weird.

NOtice something else, when hovering over a struct it also says :
class FooStruct, where I guess we should say : struct FooStruct , right ?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: strong enum support
« Reply #4 on: December 19, 2010, 02:10:44 pm »
just found one little hickup.

When I tooltip over the enum class type, the tooltip shows 2 things :

enum Foo {}
class Foo {}


where it should only show :

enum class Foo {}

Note from time to time, it only says enum Foo. A bit weird.


should show "enum Foo". I just reviewed the rev6759, loaden just eat the "class" keyword after enum. so

Code
enum class StrongEnum1
{
    on,
    off
};

is indeed becomes:
Code
enum StrongEnum1
{
    on,
    off
};



Code
NOtice something else, when hovering over a struct it also says : 
class FooStruct, where I guess we should say : struct FooStruct , right ?
confirmed, I think this can be fixed easily, I will look into it right now.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: strong enum support
« Reply #5 on: December 19, 2010, 02:24:01 pm »

Code
NOtice something else, when hovering over a struct it also says : 
class FooStruct, where I guess we should say : struct FooStruct , right ?
confirmed, I think this can be fixed easily, I will look into it right now.

oh, I found that there is not "struct" Token...

see the declaration:
Code
enum TokenKind
{
    // changed in order to reflect the priority
    tkNamespace     = 0x0001,
    tkClass         = 0x0002,
    tkEnum          = 0x0004,
    tkTypedef       = 0x0008, // typedefs are stored as classes inheriting from the typedef'd type (taking advantage of existing inheritance code)
    tkConstructor   = 0x0010,
    tkDestructor    = 0x0020,
    tkFunction      = 0x0040,
    tkVariable      = 0x0080,
    tkEnumerator    = 0x0100,
    tkPreprocessor  = 0x0200,
    tkMacro         = 0x0400,

    // convenient masks
    tkAnyContainer  = tkClass    | tkNamespace   | tkTypedef,
    tkAnyFunction   = tkFunction | tkConstructor | tkDestructor,

    // undefined or just "all"
    tkUndefined     = 0xFFFF
};

so, the "struct" is recorded as "class"...

not easy to change, because we need to change a lot if we add a new "struct" type.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.