Check if function argument can be handled in CT

Andrey saasecondbox at yandex.ru
Wed Apr 24 07:53:47 UTC 2019


Hi all,
Do you know can we detect that some argument of a function can be 
handled in CT?
For example:
> int value1 = 10;
> someFunction(value1);
> int value2 = getValueFromUserInput();
> someFunction(value2);

> void someFunction(int arg)
>{
>    static if(argCanBeHandledInCT(arg))
>    {
>        // perform some calculations during compilation
>    }
>    else
>    {
>        // perform some calculations during runtime
>    }
>}

Such thing would be good for code optimisation.
For example we pass some strings as arguments and in function 
they are concatenated. So instead of concating them in RT (and 
allocating memory) we can do all these actions in CT and get one 
resulting string.


More information about the Digitalmars-d-learn mailing list