Solution to "statement is not reachable" depending on template variables?
QAston via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Mar 16 04:47:35 PDT 2016
On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote:
> Hi all,
> I've found discussions, but not an actual "recommended"
> solution for the problem of "statement is not reachable"
> warnings in templates with early returns, e.g.:
> ```
> bool nobool(T...)() {
> foreach (i, U; T) {
> static if (is(U == bool)) {
> return false;
> }
> }
> return true; // emits "Warning: statement is not reachable"
> }
>
> [...]
On Wednesday, 16 March 2016 at 11:18:36 UTC, Johan Engelen wrote:
import std.meta;
template isBool(U)() = is(U == bool);
static if (!allSatisfy!(isBool, T)) {
return true; // no longer emits a warning
}
Something like this should work.
More information about the Digitalmars-d-learn
mailing list