Solution to "statement is not reachable" depending on template variables?
Johan Engelen via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 18 02:28:57 PDT 2017
Reviving this thread to see whether anything has changed on the
topic.
I now have this monster:
```
struct FMT {
// has immutable members. FMT cannot be assigned to.
}
FMT monsterThatCompilerAccepts(T)(){
alias TP = Tuple!(__traits(getAttributes, T));
foreach(i, att; TP){
static if( ... ) {
return FMT( ... );
}
// Make sure we return a default value in the last
iteration.
// Prevents "statement not reachable" warning when placed
here instead of outside the foreach.
else static if (i + 1 == TP.length) {
return FMT( ... );
}
}
static if (TP.length == 0) {
return FMT( ... );
}
}
FMT codeThatIsUnderstandableButNotAccepted(T)(){
alias TP = Tuple!(__traits(getAttributes, T));
foreach(i, att; TP){
static if( ... ) {
return FMT( ... );
}
}
return FMT( ... );
}
```
Thanks,
Johan
More information about the Digitalmars-d-learn
mailing list