d的is与中

原文
is表达式

int func();

static if (is(typeof(func) R == return))
    pragma(msg, R);

std.traits.ReturnType实现为:

template ReturnType(alias func)
if (isCallable!func)
{
    static if (is(FunctionTypeOf!func R == return))
        alias ReturnType = R;
    else
    static assert(0, "无中型");
}

ReturnType比原始IsExpression干得稍微多一点,因为它可确定:

struct G
{
    int opCall (int i) { return 1;}
}
posted @ 2023-01-19 09:05  zjh6  阅读(15)  评论(0)    收藏  举报  来源