UDA and ReturnType!(__traits...) doesn't work
Meta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun May 3 10:41:07 PDT 2015
On Sunday, 3 May 2015 at 17:22:00 UTC, filcuc wrote:
> Hi all,
> i'm working in the generation of the code but i'm failing in
> extracting a function return type when invoking the
> ReturnType!(T) type trait and mixing it with
> __traits(getMember) function.
> Can anyone help me? or explaining what is happenning?
> i've created a gist here:
> https://gist.github.com/filcuc/14c3a6cac89beb69cccd
>
> The error message is the following:
>
> main.d-mixin-58(58): Error: template instance
> main.Person.ReturnType!(name) does not match template
> declaration ReturnType(func...) if (func.length == 1 &&
> isCallable!func)
> main.d-mixin-58(58): Error: template instance
> std.traits.ReturnType!(Monitor) does not match template
> declaration ReturnType(func...) if (func.length == 1 &&
> isCallable!func)
> main.d(73): Error: template instance main.IterateUDA!(Person)
> error instantiating
Try adding the following around your 'string returnType = ...'
code:
static if(isSomeFunction!(__traits(get member, T, member))
{
...
}
The problem is that you're looping over all the fields in T,
including the data members which obviously don't have a return
type. I guess ReturnType should probably use a static assert to
give a better error message.
More information about the Digitalmars-d-learn
mailing list