jeudi 19 octobre 2017

Does logical short-circuiting not work with if-constexpr?

With normal if condition, short circuiting works.

However with an attempted short circuit for if-constexpr doesn't work:

#include <iostream>
template <typename ... Args>
void foo(Args... args) {
    std::string a; 
    // for the call of foo, sizeof...(args) = 0, so a > 2 shouldn't be evaluated.
    if constexpr (sizeof...(args) == 0 || a > 2) {
        std::cout << "ASD" << '\n';
    }
}

int main() {
   foo();
}

Demo

Aucun commentaire:

Enregistrer un commentaire