Prevent self-comparison without taking the address
IchorDev
zxinsworld at gmail.com
Thu Jul 25 11:43:15 UTC 2024
On Thursday, 25 July 2024 at 10:50:04 UTC, Dom DiSc wrote:
> Can I replace this pattern with ```(x is this)``` or are there
> some special cases where this doen't work?
When a parameter is `ref` it is treated as a value type (i.e. it
has value semantics), even though it is a reference; therefore an
identity expression of `x is this` will check whether the bits in
`x` and `this` are identical:
https://dlang.org/spec/expression.html#identity_expressions
Using the reference operator (`&`) on something that is `ref`
returns its pointer form, which is what you want to compare.
TL;DR: No, `is` will compare the struct data not the pointers.
More information about the Digitalmars-d-learn
mailing list