d版运行时错误

原文

if (vkCreateInstance(&createInfo, null, &instance) != VK_SUCCESS) {
    ...
}

官方错误基于异常:

class VKException : Exception
{
    this(string msg)
    {
        super(msg);
    }
}

void _()
{
   if (vkCreateInstance(&createInfo, null, &instance) != VK_SUCCESS) {
      throw new VKException("不能创建VK实例")
   }
}

std.exception.enforce更可读.

enforce(vkCreateInstance(&createInfo, null, &instance) == VK_SUCCESS,"不能创建VK实例");

也可抛

enforce!VKException(/* ... */);

这样可编译语句:

__traits(compiles,{int* cMutable = &c;})
posted @ 2022-11-10 09:23  zjh6  阅读(11)  评论(0)    收藏  举报  来源