[Issue 6453] New: Allow multiple invariant per struct/class

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Aug 8 03:19:06 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=6453

           Summary: Allow multiple invariant per struct/class
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: simendsjo at gmail.com


--- Comment #0 from simendsjo <simendsjo at gmail.com> 2011-08-08 03:19:03 PDT ---
I would like to use a template mixin to add some fields to a struct, but I'd
also like the template to add additional invariant checks without having to
remember to add this for all struct/classes that mixes in this code.

class C {
    int a;
}

mixin template EmbedC() {
    C _c;

    // oops.. more than one invariant
    invariant() {
        assert(_c);
    }

    void close() {
        _c = null;
    }
}

struct S {
    int i = 10;
    invariant() {
        assert(i >= 10);
    }

    mixin EmbedC!();
}

void main() {
    S s;
    s.close();
    s._c.a = 10; // access violation, but I want assertion from invariant
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list