Manually check struct invariants

Paul Backus snarwin at gmail.com
Tue Mar 23 23:27:54 UTC 2021


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.


More information about the Digitalmars-d-learn mailing list