c++17 provides if constexpr, in which:
the value of condition must be a contextually converted constant expression of type
bool. If the value istrue, then statement-false is discarded (if present), otherwise, statement-true is discarded
Is there a way to use this in a for-statement as well? To unroll a loop at compile time? Id like to be able to do something like this:
template <int T>
void foo() {
for constexpr (auto i = 0; i < T; ++i) cout << i << endl;
}
Aucun commentaire:
Enregistrer un commentaire