Is there any performance penalty for static if?

Ferhat Kurtulmuş aferust at gmail.com
Wed May 15 22:03:39 UTC 2019


Hi,

Maybe I already know the answer, but have to be sure about this. 
I am emulating this cpp code "int val = mat.at<int>(row, col)" 
like:

T at(T)(int row, int col){
         static if (T.stringof == "float"){
             return getFloatAt(row, col);
         } else static if (T.stringof == "double"){
             return getDoubleAt(row, col);
         } else static if (T.stringof == "int"){
             return getIntAt(row, col);
         } else static if (T.stringof == "ubyte"){
             return getUCharAt(row, col);
         } else static if (T.stringof == "byte"){
             return getSCharAt(row, col);
         } else static if (T.stringof == "short"){
             return getShortAt(row, col);
         }
     }
This works as expected, and I know conditions of "static if" is 
determined at compile time  and I assume no speed penalty here?


More information about the Digitalmars-d-learn mailing list