Pattern matching is-expressions

Stefan Koch uplink.coder at
Wed Aug 19 13:14:22 UTC 2020

On Wednesday, 19 August 2020 at 13:03:59 UTC, Dennis wrote:
  Also they are not
> complete (there is trait for checking if something is an enum),
The expression is(T == enum) works, and does detect if something 
has an enum type.
Are you talking about detecting a manifest constant?

> (I know there's a Pull Request in dmd for adding 
> `__traits(isDynamicArray)`)
Indeed and it shows a 16% performance improvement over using the 
isDynamicArray template in phobos. (Since it doesn't have to 
match anything, it just returns a part of the compiler internal 
But even if that weren't the case I find it much more intuitive 
than pattern matching is expressions.

> The advantage of traits is that they can be more future proof 
> however. `isIntegral` would still work unlike `is(T : long)` 
> even if `cent` and `ucent` types are added, or even if (ulong : 
> long) implicit conversion gets deprecated.
True I hadn't even considered that aspect yet.

> I wish the redundant traits (isAssociativeArray, isStaticArray) 
> weren't there since they are completely covered by is 
> expressions though.

The is expressions are more expensive, because of the matching 

More information about the Digitalmars-d mailing list