vendredi 6 novembre 2020

C++ bool template parameter and compile time if

I have the following function

template <bool c>
void func()
{
    ...
    if (c) {
        // do something
    } else {
        // do something else
    }
}

This function is to be used several time inside a loop:

for (...) {
    func<true>();
}

I would like to know it the if inside func is done compile-time, run-time, or if it is left to the compiler.

Aucun commentaire:

Enregistrer un commentaire