dlang比较类型:不能对类型使用'=='

Cha*_* L. 3 static-analysis d

我的代码中有以下行:

static if (typeof(val) == string) {
Run Code Online (Sandbox Code Playgroud)

它没有编译并返回错误Error: incompatible types for ((string) == (string)): cannot use '==' with types.检查变量类型的正确方法是什么?

Ada*_*ppe 7

正确的方法是使用它周围的is表达式:is(A == b)像这样:

static if (is(typeof(val) == string)) {
Run Code Online (Sandbox Code Playgroud)