?
=?ISO-8859-1?Q?Mattias_Br=E4ndstr=F6m?=
Hi!
Suppose I want to do some thing like this:
enum X { A, B, C, D };
int main()
{
X a1[] = { A, B, C, D };
int size_a = sizeof(a1) / sizeof(X);
for (int i = 0; i < size_a; ++i)
cout << a1 << endl;
}
What I try to illustrate here is that I want to iterate over the values
in the enum X in the order that they are decalred or rather iterate over
the values in order starting with the smallest and eneing with the largest.
Is there a safe way to do this with an enum that will work even if X is
redefined to be something like this:
enum X { D, C, B, A}
or
enum X { A = 0, B = 1, C = 100, D = 42 };
Perhaps it is more appropriate to solve this with a class:
class X
{
public:
static const X A;
static const X B;
static const X C;
static const X D;
const X& MinValue() const;
const X& MaxValue() const;
X& operator++();
private:
X(int i);
int v_;
}
What are your thoughts on this?
:.:: mattias
Suppose I want to do some thing like this:
enum X { A, B, C, D };
int main()
{
X a1[] = { A, B, C, D };
int size_a = sizeof(a1) / sizeof(X);
for (int i = 0; i < size_a; ++i)
cout << a1 << endl;
}
What I try to illustrate here is that I want to iterate over the values
in the enum X in the order that they are decalred or rather iterate over
the values in order starting with the smallest and eneing with the largest.
Is there a safe way to do this with an enum that will work even if X is
redefined to be something like this:
enum X { D, C, B, A}
or
enum X { A = 0, B = 1, C = 100, D = 42 };
Perhaps it is more appropriate to solve this with a class:
class X
{
public:
static const X A;
static const X B;
static const X C;
static const X D;
const X& MinValue() const;
const X& MaxValue() const;
X& operator++();
private:
X(int i);
int v_;
}
What are your thoughts on this?
:.:: mattias