Hello Nick,
"Sean Kelly" <s...@invisibleduck.org> wrote in message
news:hfelka$rh...@digitalmars.com...
Nick Sabalausky Wrote:
I just noticed in D1 that the values for the cases in a switch must
be
known
at compile-time (btw, the docs don't seem somewhat vague on that).
Is
this
also true in D2? If so, I don't suppose we could get that changed
before
the
book? It's a real PITA for dynamic code.
int x = 1, y = 1;
switch( z )
{
case x:
...
case y:
...
}
What should this do? Throw an exception perhaps?
As I mentioned earlier, that should be semantically equivilent to:
int x = 1, y = 1;
if(z == x)
{ ... }
else if(z == y)
{ ... }
In fact, it's already semantically equivilent to that, except that x
and y are currently required to be known at compile-time.
Just jumping a ways down this rabbit hole...
struct S { int i; int opCmp(S s) { return i-- == s.i++; }
{
S a,b,c,d,e;
...
switch(a)
{
case b: break;
case c: break;
case d: break;
case e: break;
}
}
Oh, boy. What the hack does the above do?