switch case for constants-only?

Nick Sabalausky a at a.a
Sat Dec 5 13:32:26 PST 2009


"Don" <nospam at nospam.com> wrote in message 
news:hfeilp$m1b$1 at 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.
>
> Switch with constant values is completely different to a switch statement 
> with variables -- it's reasonable to expect O(1) case comparisons if all 
> the values are known at compile time, but I think that's impossible with 
> variable cases.

So who's expecting switch with variable cases to be O(1)?

> Allowing switch with variable cases at the expense of constant cases would 
> be a real PITA for non-dynamic code. You'd need some way of handling both.

Well, yea, that's what I'm saying: it should handle both.





More information about the Digitalmars-d mailing list