Scratchpad for compile-time control flow
void foo() { | |
for (auto x : tuple) { | |
if (runtime-bool) // ill formed | |
constexpr break; | |
} | |
} | |
void foo() { | |
for (auto x : tuple) { | |
if constexpr (compile-time-bool) // yes! | |
constexpr break; | |
} | |
} | |
void foo() { | |
for (auto x : tuple) { | |
constexpr break; // always breaks at the first iteration of the loop | |
} | |
} | |
void foo() { | |
for (auto x : tuple) { | |
xxx; | |
if constexpr (compile-time-bool) | |
constexpr break; | |
yyy; // not instantiated when the `constexpr break` is hit | |
} | |
} | |
void foo() { | |
for (auto x : tuple) { | |
xxx; | |
if constexpr (compile-time-bool) | |
return z; | |
yyy; // not instantiated when the `return` is hit | |
} | |
} | |
template<typename T> | |
void f() { | |
if constexpr (compile-time-bool) | |
constexpr return; | |
xxx; // never instantiated if the `constexpr return` is hit | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment