Charles L.
Charles L.

Reputation: 6305

dlang compare types: cannot use '==' with types

I have the following line in my code:

static if (typeof(val) == string) {

It is not compiling and returning the error Error: incompatible types for ((string) == (string)): cannot use '==' with types. What is the correct way to check the type of a variable?

Upvotes: 4

Views: 585

Answers (1)

Adam D. Ruppe
Adam D. Ruppe

Reputation: 25605

The correct way to do it is to use an is expression around it: is(A == b) like this:

static if (is(typeof(val) == string)) {

Upvotes: 8

Related Questions