The following is supposed to fill the members of `test` with the content of `assocarray`:
import std;
void main(){
struct Test {
int a;
}
Test test;
auto assocarray = [
"a": 1
];
static foreach(member; __traits(allMembers, Test)) {
mixin(iq{
writeln("$(member)");
test.$(member) = assocarray.get("$(member)", -1);
}.text);
}
writeln(test.a);
assert(test.a == 1);
}
Output:
$(member)
-1
core.exception.AssertError@.\test_token_interpolation.d(22): Assertion failure
It looks like token strings are "tokenized" before interpolation and not after, which results in "string" tokens being completely ignored for interpolation.
Comment #1 by robert.schadek — 2024-12-13T19:35:24Z