Static if to compare two types are the exact same

Andrej Mitrovic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 6 12:29:54 PDT 2015


On 4/6/15, Jonathan via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:
> What's the best way to do this? I'm assuming this should be best
> practice:
> http://dlang.org/traits.html#isSame
>
> struct S { }
> writeln(__traits(isSame, S, S));
>

I'm not even sure when or why this trait was introduced, but you could
use a simple is() expression for this, e.g.:

static if (is(T == S)) { ... }


More information about the Digitalmars-d-learn mailing list