Re: Switch constants

2010-11-14 Thread BCS
Hello bearophile, In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x * Foo!(x - 1); } int bar(

Re: Switch constants

2010-11-13 Thread bearophile
Daniel Murphy: > switch(x) > { > case 0: >break; // what is x here? > case 1: >goto case 0: > } > etc You are right. Thank you for all the answers. Bye, bearophile

Re: Switch constants

2010-11-13 Thread Stanislav Blinov
bearophile wrote: In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? template Foo(uint x) { static if (x <= 1) enum Foo = 1; else enum Foo = x

Re: Switch constants

2010-11-13 Thread Daniel Murphy
"bearophile" wrote in message news:ibn320$2uc...@digitalmars.com... > In a not-ranged cases body, like in the program below (that doesn't > compile), the switch variable is a compile-time constant, so why doesn't > the compile see x as constant there? In switch statements, you can do stuff lik

Re: Switch constants

2010-11-13 Thread Dmitry Olshansky
On 14.11.2010 1:21, bearophile wrote: In a not-ranged cases body, like in the program below (that doesn't compile), the switch variable is a compile-time constant, so why doesn't the compile see x as constant there? Well, there is fall-through ;) And there still could be goto's. In essence "c