i got a lot of replies during my hiatus, but unfortunately, none of them
seem to be thinking the same way as me with regards to what a smarter
enum type would be like.
Victor said:
mostly it prevents the enum member names [...]
Thank you for your explanation and your psychology (and not psychiatry)
lesson (do you know the difference? I probably don't, I only pretend
I do). However, I just wanted to point out that you may have started
with a wrong premise. Enums don't have members.
semantics. whatever you want to call them, i was clearly referring to
the constituent entities of an enumeration.
btw, you were incorrect, psychiatry was the correct term for what i was
doing. and yes, i am quite familiar with the difference. this may aid
you the next time you get confused: if a man says to a psychiatrist, "i
want to kill everyone i know", the psychiatrist will ask him to tell him
more, and in the course of their conversation help the man understand
why he feels so much anger, and help him work it out non-agressively.
if the same man were to say the same thing to a psychologist, the
psychologist would say, "wow, thanks for telling me that", and note it
in his journal.
I don't think that what you're trying to do is worth your time. My
understanding is that you are trying to design an enum that has some minor
added features over a standard enum. Basically, it's an enum that also
gives you the ability to define class functionality, such as methods and
operators.
no, that is incorrect, but that is my fault. i was more concerned with
musing out a potential starting point for a solution than explaining
what i was after. one of the things i am really hoping to prevent is this:
typedef enum { a, b, c } A;
typedef enum { x, y, z } Z;
A foo = a;
Z bar = x;
a == x; // will test true, though it is obviously not
and this:
// foo.hpp
typedef enum { a, b, c } foo_enum;
// changed to typedef enum { a, e, i } foo_enum;
// bar.hpp
typedef enum { d, e, f } bar_enum;
// changed to typedef enum { b, c, d } bar_enum;
// file.cpp
#include "foo.hpp"
#include "bar.hpp"
void func(foo_enum foo)
{
// will break silently with the changes
switch (foo)
{
case c: // it's a c
case b: // it's a b
default: // must be an a
}
}
i am not particularly interested in adding iteration to my enumerations,
and while printing the symbolic names of my enumerations would be nice,
it's not really necessary. really, i'm not interested in adding any
functionality at all - all i'm after is stricter type- and name-safety.
and even then, only in debug compile mode if i have to.
incidently, i had another look at that magazine, and the big trick was:
typedef enum { a, b = 1234, c = 0xFFFFFFFFU } enum_type;
cout << c;
cout << (b > c);
Thomas said:
This has been done before.
Use your favorite search engine and search for
"Dan Saks enumeration". You could also supplement
your search with "Scott Meyers enumeration"
and "Jim Hyslop enumeration". These folks have
worked out the conversion of an enumeration into
a type.
In today's world, your best effort should be spent
researching before designing. If its been done
before, either use it, tailor it, or improve it.
i really hate pointing out the obvious, but if i were going to go do it
all on my own, why would i be here *specifically* asking if anyone has
seen it done before?
as for the links, they may be exactly what i was looking for, but i
couldn't find anything relevant under hyslop or meyers (too much other
crap came up), and saks seemed more concerened with adding iteration to
enumerations, which i am not interested in. does anyone have more
specific information i could use to search? i suspect that hyslop has
dealt with what i'm after (based on his other work), but maybe meyers
has, too.
mark