[Template] Mixins and foreach
Nicholas Wilson
iamthewilsonator at hotmail.com
Sun Oct 1 01:05:56 UTC 2017
struct MyType
{
void* raw;
static struct Info
{
@(42) int foo;
}
mixin generateGetInfo!MyTypeGetInfo;
}
extern(C) void MyTypeGetInfo(void*,int,size_t,void*size_t*);
mixin template generateGetInfo(alias func)
{
foreach(field; typeof(this).Info.tupleof)
{
mixin("@property " ~ typeof(field).stringof ~ " " ~
field.stringof ~ "()" ~
" { " ~
" typeof(return) ret;" ~
func.stringof ~ "(this.tupleof," ~
__traits(getAttributes, field)[0] ~ ",ret.sizeof,&ret,null);" ~
"return ret; }");
}
}
Fails with
Error: declaration expected, not 'foreach'
Error: no identifier for declarator typeof(this).Info.tupleof
Error: declaration expected, not ')'
I also tried a double mixin, one for the foreach and one for the
mixin to no avail. How do I do a foreach in a [template] mixin to
procedurally inject multiple declarations ? Static foreach is not
an option as I am using LDC.
More information about the Digitalmars-d-learn
mailing list