is Expression

You will get to learn about the “is” Expression in this lesson.

The is expression is not related to the is operator that we saw in the null Value and the is Operator chapter, neither syntactically nor semantically:

a is b // is operator, which we have seen before 

is (/* ... */) // is expression

The is expression is evaluated at compile time. It produces an int value, either 0 or 1, depending on the expression specified in parentheses. Although the expression that it takes is not a logical expression, the is expression is used as a compile time logical expression. It is especially useful in static if conditionals and template constraints.

The condition that it takes is always about types, which must be written in one of several syntaxes.

is (T)

is (T) determines whether T is valid as a type. It is difficult to come up with examples for this use at this point. We will take advantage of it in later chapters with template parameters.

Get hands-on with 1200+ tech skills courses.