Static if to compare two types are the exact same

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 6 12:30:50 PDT 2015


On Mon, 06 Apr 2015 19:16:33 +0000, Jonathan 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));


struct S {}

auto s0 = S();
auto s1 = S();

static if (is(typeof(s0) == typeof(s1))) {
  pragma(msg, "Woe to the Republic.");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150406/4a83a308/attachment.sig>


More information about the Digitalmars-d-learn mailing list