can't access an alias created inside an if statement

Simen Kjærås simen.kjaras at gmail.com
Wed Aug 5 09:39:47 UTC 2020


On Wednesday, 5 August 2020 at 09:32:58 UTC, Flade wrote:
> Thanks! You see it should work but the thing is. I'm using it 
> inside a function. I'm checking for one of the function's 
> parameter (if parameter == false) and it says that "the 
> variable `parameter` cannot be read at compile time. Do you 
> know if there is a way to fix this?

As the error message says, the value must be known at compile 
time. Most likely, you can simply pass it as a template parameter:

     void fun(bool parameter)(int arg1, string arg2) {
         static if (parameter) {
         }
     }

     void main() {
         fun!true(1, "foo");
         fun!false(19, "bar");
     }

--
   Simen


More information about the Digitalmars-d-learn mailing list