Template mixin statements?
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Jan 18 14:54:02 UTC 2019
On Fri, Jan 18, 2019 at 11:07:10AM +0000, NaN via Digitalmars-d wrote:
> Template mixins can only mixin declarations. Was it ever considered to
> allow them to mixin statements? Is it ever likely to be added? Or are
> there reasons it wasnt allowed?
>
> Thanks.
I don't remember the rationale for this, but if you want to mixin
statements, you can use the Do template in the following workaround:
import std.stdio;
mixin template Do(alias fun) {
int _dummy = { fun(); return 0; }();
}
mixin template MyMixin() {
string strDecl = "abc";
mixin Do!({ writeln("look ma, a statement!"); });
int intDecl = 123;
mixin Do!({ writeln("look ma, another statement!"); });
}
void main() {
mixin MyMixin!();
writeln(strDecl);
writeln(intDecl);
}
It's a bit ugly, but it works.
T
--
Bomb technician: If I'm running, try to keep up.
More information about the Digitalmars-d
mailing list