d隐式整转换

import std.stdio: writeln;

void foo(uint x)
    in (x >= 0)
{//删除该前条件,因为x为`正`总是`>=0`.
    writeln(x);
}

void foo(ushort x)
    in (x >= 0)
{
    writeln(x);
}

void main() {
    int x = -1;
    foo(x); //打印4294967295
    short y =-1;
    foo(y); //打印65535
}

前条件运行前,隐式转换xy正/正短.

posted @ 2022-05-25 08:29  zjh6  阅读(18)  评论(0)    收藏  举报  来源