Mixin/static if issue
DLearner
bmqazwsx123 at gmail.com
Wed Aug 25 22:52:23 UTC 2021
On Wednesday, 25 August 2021 at 22:33:00 UTC, H. S. Teoh wrote:
[...}
>
> I think what you meant to write is:
>
> static if (typeof(mixin(VarName)).stringof == "uint") {
>
> You want the type of the variable named by VarName, not the
> type of VarName.
>
>
> T
I understand your reasoning, but:
```
void main() {
import std.stdio;
uint TestVar = 5;
string mxnWrite_Size_t(string VarName) {
static if (typeof(mixin(VarName)).stringof == "uint") {
return `write("` ~ VarName ~ `");`;
} else {
return `writeln("Apparently TestVar not a uint");`;
}
}
mixin(mxnWrite_Size_t("TestVar"));
}
```
produced Error: variable `VarName` cannot be read at compile time
More information about the Digitalmars-d-learn
mailing list