static-if cant compile
Rikki Cattermole via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jul 19 05:21:41 PDT 2015
On 20/07/2015 12:17 a.m., Clayton wrote:
> Pardon me for trivial question, Am new to D.
>
>
> Why would a statement as below fail to compile. The plan is to do some
> computation at compile-time hence considering the static-if statement
> which fails to compile. The regular if-statement compiles but is not
> useful since it is a runtime construct.
>
> The error message I get is : Error: variable i cannot be read at
> compile time
>
>
>
>
> foreach( i; 0..size-1){
> static if ( i == -1 ){
> //Do something
> }
>
> }
static if is for compile time known constants.
if is for runtime variables.
In this case it would be a runtime variable even if it is known at
compile time.
Known at compile time != run at compile time. They overlap yes, just not
the same thing.
More information about the Digitalmars-d-learn
mailing list