Manually check struct invariants
Q. Schroll
qs.il.paperinik at gmail.com
Wed Mar 24 01:15:13 UTC 2021
On Tuesday, 23 March 2021 at 23:27:54 UTC, Paul Backus wrote:
> On Tuesday, 23 March 2021 at 22:22:12 UTC, Q. Schroll wrote:
>> For a class object obj, one can use assert(obj) to get its
>> invariants checked. How to do this for structs?
>
> https://dlang.org/spec/expression.html#assert_expressions
>
>> If the first AssignExpression is a pointer to a struct
>> instance for which a Struct Invariant exists, the Struct
>> Invariant must hold.
>
> So, you would write `assert(&obj)` for a struct instance.
I searched for it, but while for some reason, my brain read "If
the first AssignExpression is a reference to a class instance for
which a Class Invariant exists, the Class Invariant must hold."
it failed to do so for the next sentence.
Thank you.
More information about the Digitalmars-d-learn
mailing list