Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are 'is' statements in D?

Tags:

traits

d

Inside the std.traits module, I can find a line similar to:

assert(is(Unqual!(int) == int));

I know that Unqual removes any type modifiers like immutable, but what does the 'is' do? How is it different from an if statement and when should it be used?

like image 635
Jeroen Avatar asked Apr 29 '14 19:04

Jeroen


Video Answer


2 Answers

is(Unqual!(int) == int) is an expression, not a statement. The line you posted does not exist in std.traits.

I assume you mean the following line:

static assert(is(Unqual!int == int));

See the documentation for IsExpression.

like image 177
Vladimir Panteleev Avatar answered Sep 26 '22 17:09

Vladimir Panteleev


is is an expression that allows for example to check if types are equal, if 1 type is subtype of another or if T a class/enum/struct etc.

The code you posted checks if specified type does not have any modifiers.

For more information se D Language Documentation about IsExpression.

like image 45
Robik Avatar answered Sep 25 '22 17:09

Robik