​U().func!0​​​不是调用吗?
这可行,但看起来很奇怪,我正在检查​​​UDA​​表达式的类型:

@(U().func!0) int b;
pragma(msg,__traits(getAttributes,b));//tuple(U().func)
pragma(msg,typeof(__traits(getAttributes,b)[0]));//purenothrow@nogcref@safeU()return
pragma(msg,ReturnType!(__traits(getAttributes,b)[0]));//U
pragma(msg,is(typeof(__traits(getAttributes,b)[0]):U));//false
pragma(msg,hasUDA!(b,U));//false

包装在​​lambda​​中.

import std.traits;

alias type = ReturnType!(() => U().func!0);

或无需导入​​phobos​​:

alias type = typeof((() => U().func!0)());
//这样
auto ref eval(T)(auto ref T expr) { return expr; }
alias type = typeof(eval(U().func!0)));

我的情况是,用户可编写​​UDA​​​表达式,我检查它是否是使用​​hasUDA!(sym,U)​​​和​​getUDAs!(sym,U)​​​的​​U​​​类型.用户使用​​U()​​​或​​U().func!0()​​​,则一切正常.但因为类型不是​​U​​​,​​U().func!0​​​不会.因此,要处理这个用例,似乎需要实现自己的基于​​ReturnType​​​的​​hasUDA​​​和​​getUDAs​​​.
问题是,​​​typeof(U().func!0)​​​为何与​​typeof(U().func!0())​​​的类型不一样.
​​​UFCS​​​中也存在不一致,​​类型​​​根据函数是​​成员​​​还是​​自由​​​(即使用​​ref U​​​替换​​auto ref​​)

struct U
{
ref U func(int i)() { return this; }
}
ref U func2(int i)(ref U u) { return u; }

void main()
{
U u;
pragma(msg, typeof(u.func!0));//pure nothrow @nogc ref @safe U() return
pragma(msg, typeof(u.func2!0));//U
}