using "invariant" with structs ... possible to call when a field value is set??

james.p.leblanc james.p.leblanc at gmail.com
Sun Aug 8 11:30:41 UTC 2021


Hello,

With structs, I understand that "invariant checking" is called 
(from dlang tour):

     It's called after the constructor has run and before the 
destructor is called.
     It's called before entering a member function
     invariant() is called after exiting a member function.

But, is is possible to have the invariant checking be performed
whenever a field is directly set?

For example, suppose a struct "S", has a field "x".  I would like 
to
have invariance check in cases such as:

S.x = 4;

Maybe there is a hidden set field function that gets called that
might be exploitable??

Thoughts on this?  Possible?  Better paths that I should consider?

Best Regards,
James




More information about the Digitalmars-d-learn mailing list