Follow TV Tropes

Following

Is C++ easy to understand

Go To

Medinoc from France (Before Recorded History)
#201: Jun 7th 2011 at 9:06:03 AM

[up]I don't see the utility of iterating over them. I use them for mutually exclusive statuses and other qualifiers I never have to enumerate, except for some debug things (where I solve it by adding a MYENUM_MAX value, counting from 0 to it, and casting)

"And as long as a sack of shit is not a good thing to be, chivalry will never die."
Fighteer Lost in Space from The Time Vortex (Time Abyss) Relationship Status: TV Tropes ruined my love life
Lost in Space
#202: Jun 7th 2011 at 9:09:07 AM

"automatically assign consecutive values"? I don't understand what this means.

I already said what value an enum has in VB/VBA; that is, to give the editor the ability to provide context-sensitive tooltips and inline autocompletion.

"It's Occam's Shuriken! If the answer is elusive, never rule out ninjas!"
Yej See ALL the stars! from <0,1i> Since: Mar, 2010
See ALL the stars!
#203: Jun 7th 2011 at 9:15:15 AM

[up] The following is a valid C# enum:

 enum Direction 
{
Null, Up, Down, Left, Right
}
The compiler assigns the actual values at compile-time, so that, say, Up || Right works as expected.

edited 7th Jun '11 9:16:01 AM by Yej

Da Rules excuse all the inaccuracy in the world. Listen to them, not me.
Fighteer Lost in Space from The Time Vortex (Time Abyss) Relationship Status: TV Tropes ruined my love life
SilentReverence adopting kitteh from 3 tiles right 1 tile up Since: Jan, 2010
adopting kitteh
#205: Jun 7th 2011 at 12:57:05 PM

Enums in C++ are too weak to do much of the interesting stuff that one can do in other languages. They're not realy strongly typed, which is in and of itself about half of the problem. That's fixed with enum-class in C++\\dx, but still leaves a lot to be desired for those among us who must support old systems...

The one advantage of enums over merely declaring a set of constants is that enums are attributed to the surrounding scope, regardless of it being a namespace or class, which means they can be used to declare values in contexts where otherwise fully typed variables can not be declared. Of course, this shows better and more prominently in template metaprogramming (particularly in selection policies).

As for iteration, doing it over an enum is nifty to have when you use enumeration values as associative keys (which you shouldn't be doing anyway, though). If you really need an iterable enum, Boost Vault does have a perl-assisted generator of iterable, almost-strongly typed, string-compatible enums (go figure), and it's still pretty much trivial to implement it if you are comfortable with static arrays and the iterator traits concept otherwise.

edited 7th Jun '11 5:54:00 PM by SilentReverence

Fanfic Recs orwellianretcon'd: cutlocked for committee or for Google?
Add Post

Total posts: 205
Top