mixing (else) static if inadvertently with else if

rikki cattermole rikki at cattermole.co.nz
Sat May 18 12:09:14 UTC 2019


Works:

---
import std.stdio;

void main()
{
     func!true(false);
     func!false(false);
     func!false(true);
}

void func(bool A)(bool b) {
     static if (A) {
         writeln("a");
     } else if (b) {
     	writeln("b");
     } else {
      	writeln("c");
     }
}
---

This works because that static if + if + else actually is:

---
static if (A) {
	...
} else {
	if (B) {
		...
	} else {
		...
	}
}
---

This works as intended.


More information about the Digitalmars-d-learn mailing list