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.

Reply via email to